How to turn the query into a class so that other programs call this class how to write and call,
Program is as follows: textBox1 enter text to the text in the textBox1 lookup table contains the text field
//query button click event
Private void button1_Click (object sender, EventArgs e)
{
If (textBox1 Text!="")
{
String connStr="Data Source=. Initial Catalog=test; User ID=sa; Password=root ";
SqlConnection conn=null;
Try
{
Conn=new SqlConnection (connStr);
Conn. The Open ();
String SQL="select * from course where the name like '%" + textBox1. Text. The Trim () + "%'";
SqlDataAdapter sda=new SqlDataAdapter (SQL, conn);
The DataSet ds=new DataSet ();
Sda. The Fill (ds);
DataGridView1. The DataSource=ds. Tables [0];
}
The catch (Exception ex)
{
MessageBox. Show (" error!" + ex. Message);
}
The finally
{
If (conn!=null)
{
Conn. Close ();
}
}
}
}