. CS file content:
Private void getdata ()
{
Try
{
// Specify a connection string. Replace the given value with
// Valid connection string for a northwind SQL Server Sample
// Database accessible to your system.
String connectionstring =
"Integrated Security = sspi; persist Security info = false;" +
"Initial catalog = northwind; Data Source = localhost ";
Sqlconnection connection = new sqlconnection (connectionstring );
// create a dataset.
dataset DATA = new dataset ();
data. locale = system. Globalization. cultureinfo. invariantculture;
// Add data from the customers table to the dataset.
string SQL = "select * from MERs where customerid = '" + this. textbox1.text + "'";
sqldataadapter masterdataadapter = new
sqldataadapter (SQL, connection);
masterdataadapter. fill (data, "customers");
This. datagridview1.datasource = data. tables [0]. defaultview;
}< br> catch (sqlexception)
{< br> MessageBox. show ("to run this example, replace the value of the" +
"connectionstring variable with a connection string that is" +
"valid for your system. ");
}< BR >}
Private void textbox1_textchanged (Object sender, eventargs E)
{
Getdata ();
}
Designer. CS File Content
Namespace windowsapplication9
{
Partial class form1
{
/// <Summary>
/// Required designer variables.
/// </Summary>
Private system. componentmodel. icontainer components = NULL;
///
/// clear all resources in use.
///
/// true if managed resources should be released; otherwise, false.
protected override void dispose (bool disposing)
{< br> If (disposing & (components! = NULL)
{< br> components. Dispose ();
}< br> base. Dispose (disposing);
}
# Region generated by Windows Form DesignerCode
/// <Summary>
/// The designer supports the required methods-do not
/// Use the code editor to modify the content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. textbox1 = new system. Windows. Forms. Textbox ();
This. Maid ();
(System. componentmodel. isupportinitialize) (This. datagridview1). begininit ();
This. suspendlayout ();
//
// Textbox1
//
This. textbox1.location = new system. Drawing. Point (3, 3 );
This. textbox1.name = "textbox1 ";
This. textbox1.size = new system. Drawing. Size (100, 21 );
This. textbox1.tabindex = 0;
This. textbox1.textchanged + = new system. eventhandler (this. textbox#textchanged );
//
// Datagridview1
//
This. Maid = system. Windows. Forms. Maid. autosize;
This. Maid = new system. Drawing. Point (3, 30 );
This. Maid = "maid ";
This. Maid. Height = 23;
This. datagridview1.size = new system. Drawing. Size (409,171 );
This. Maid = 1;
//
// Form1
//
This. autoscaledimensions = new system. Drawing. sizef (6f, 12f );
This. autoscalemode = system. Windows. Forms. autoscalemode. Font;
This. clientsize = new system. Drawing. Size (416,206 );
This. Controls. Add (this. datagridview1 );
This. Controls. Add (this. textbox1 );
This. Name = "form1 ";
This. Text = "form1 ";
This. Load + = new system. eventhandler (this. form#load );
(System. componentmodel. isupportinitialize) (This. datagridview1). endinit ();
This. resumelayout (false );
This. initialize mlayout ();
}
# Endregion
private system. Windows. Forms. textbox textbox1;
private system. Windows. Forms. datagridview datagridatagri1;
}< BR >}