C#
MSDN Tiki Hut Roadshow
Wednesday, February 18, 2009 6:30 PM - Wednesday, February 18, 2009 9:30 PM Eastern Time (US & Canada)
Welcome Time: 6:00 PM
Space Coast Credit Union Corporate Headquarters
8045 N. Wickham Road
Melbourne
Florida
32940
United States
Session 1 – jQuery with ASP.NET
- JQuery is an open source JavaScript library that has a passionate
following among Ajax developers. Microsoft is integrating the open
source JQuery library into both the ASP.NET Web Forms and ASP.NET MVC
frameworks and providing full product support. Learn how you can take
advantage of JQuery to build richly interactive client-side Ajax
applications when developing either ASP.NET Web Forms or ASP.NET MVC
applications. Also see how JQuery works...
The easiest way to upload a database to dotster is to use the sql hosting toolkit. Visual studio 2008 installs the sql hosting toolkit for you otherwise you need to download and install from the link.
Steps to do this
1) Create a database in the dotster control panel.
2) In the server explorer create a link to the database you want to upload.
3) Right click on the database and select publish to provider in the wizard make sure you select sql 2000 as the target database schema.
4) On the codeplex website they use to have a webpage available to use to help...
Change the DataType of a Column
Sometimes when you fill a DataTable the .Net framework does not get the data type right. Unfortunately once you fill a data table you can not change the data type. You can use the data adapters FillScheme method to setup the data table this will allow you to be to change the data type. Then you can fill the datatable with the data of the right type. .
VB Example
Dim conn As New SqlClient.SqlConnection("Server = .\sqlexpress; Database = NorthWind; " & _
"Integrated Security = sspi;")
Dim dt As New DataTable
Dim da As New SqlClient.SqlDataAdapter("Select * from [Order Details]",...
Draw an Icon in a DataGridViewButtonCell
Here is a simple example on how to draw in a DataGridViewButtonCell. In this example an icon is displayed when button is pushed and the icon is made invisible when its pushed again. I am storing the if the button has been pressed in the cell's tag. I use the cellPainting event to draw the icon when needed.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CSButtonColumn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
String strConn = "Server = .\\SqlExpress;Database =...
Datagrid Validation
The DataGridView has a CellValidating Event to validate the data entered. Here is how to do it with the DataGrid.
There are 2 method to do this. My method is to add a tablestyle to the datagrid. For the cells I want to validate I handle the DataGridTextBoxColumn's Textbox's Validate event. George Shepherd's method is use the CurrentCellChanged event. You can read about this method in the Windows Forms FAQ.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CSDatagrid
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
...
Printer Compatibility Library 1.0
Visual Basic 6.0 and earlier had a printer object which made it simple to print. The Printer Compatibility Library 1.0 makes it possible to use the same object with VB or C# 2005. After installing the Power Pack just add a reference to Microsoft.VisualBasic.PowerPacks.Printing.Printer
VB Sample
Imports Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim p As New Printer
p.Print("Page 1")
p.NewPage()
p.Print("Page 2")
p.EndDoc()
End Sub
End Class
C# Sample
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6;
namespace PrinterCS
{
public partial class Form1 : Form
{
public Form1()
{
...
Data From Multiple Tables in a DataGridView
There is Msdn Knowledge base article which shows how to create a JoinView class. The JoinView class is for joining 2 tables together for data binding. Basically you load 2 or more tables into a dataset and set up some data relations for the related tables. When you create the Joinview the first argument is the main table, 2nd is a list of fields you want to show, 3rd is a filter, and 4th is the field to sort on. The last 2 arguments are option. Since the article includes a vb sample I...
AutoComplete in DataGridView
In the datagridview's editing control showing event you have better access to the textboxes properties. Here is an example of adding autocomplete to the textbox.
VB Sample
Imports System.Data.SqlClient
Public Class Form1
Dim scAutoComplete As New AutoCompleteStringCollection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection
Dim ds As New DataSet
strConn = "Server = .;Database = NorthWind; Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * from [Orders]", conn)
da.Fill(ds, "Orders")
DataGridView1.DataSource = ds.Tables("Orders")
Dim cmd As New SqlCommand("Select...
.Net Framework 3.0 Text to Speech
The dot net framework 3.0 now has a managed provider for text to speech. I tested this app on a machine with windows xp service pack 2 and the Dot Net FrameWork 3.0 RC1. The link is to set up instructions for the .net framework 3.0
For this sample add a reference to system.speech, place a textbox named txtSay, a button named btnSay, and listbox named lstVoice. The application fills a list box with the installed voices on the system at startup. When you click on the button it says the text in the textbox...
Secure Strings
The SecureString is a new class that was added in the .Net framework 2.0 which allows you to store info in memory securely. The SecureString could be used to safely secure a password or credit number. The example shows how to add info to the string, prevent changes from being make to the data, and finally how to get the info back. I included c# and VB samples.
C# sample
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security;
using System.Runtime.InteropServices;
namespace SecureStringCS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
...
Full C# Archive