string struid = TextBox1.Text;
//連接數據庫
string strconn ="server = 127.0.0.1;database=xsbook;uid=sa;pwd=";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
//查詢
string strsql= "Select * from 圖書表 where 書名= '"+struid +"'";
Label1.Text = strsql;
SqlCommand mycmd = new SqlCommand(strsql,conn);
SqlDataReader rd = mycmd.ExecuteReader();
//顯示查詢結果
DataGrid1.DataSource = rd;
DataGrid1.DataBind();
//關閉連接
conn.Close();
________________________________________________________________________________________ string struid = TextBox1.Text;
//連接數據庫
string strconn ="server =127.0.0.1;database=xsbook;uid=sa;pwd=";
SqlConnection conn = new SqlConnection(strconn);
conn.Open( ) ;
//查詢
string strsql ="Select * from 圖書表";
SqlDataAdapter mycomand =new SqlDataAdapter(strsql,conn);
DataSet ds = new DataSet();
mycomand.Fill(ds,"圖書表");
//顯示查詢結果
DataGrid1.DataSource = ds.Tables["圖書表"].DefaultView;
DataGrid1.DataBind();
//關閉連接
conn.Close();
//連接數據庫
string strconn ="server = 127.0.0.1;database=xsbook;uid=sa;pwd=";
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
//查詢
string strsql= "Select * from 圖書表 where 書名= '"+struid +"'";
Label1.Text = strsql;
SqlCommand mycmd = new SqlCommand(strsql,conn);
SqlDataReader rd = mycmd.ExecuteReader();
//顯示查詢結果
DataGrid1.DataSource = rd;
DataGrid1.DataBind();
//關閉連接
conn.Close();
________________________________________________________________________________________ string struid = TextBox1.Text;
//連接數據庫
string strconn ="server =127.0.0.1;database=xsbook;uid=sa;pwd=";
SqlConnection conn = new SqlConnection(strconn);
conn.Open( ) ;
//查詢
string strsql ="Select * from 圖書表";
SqlDataAdapter mycomand =new SqlDataAdapter(strsql,conn);
DataSet ds = new DataSet();
mycomand.Fill(ds,"圖書表");
//顯示查詢結果
DataGrid1.DataSource = ds.Tables["圖書表"].DefaultView;
DataGrid1.DataBind();
//關閉連接
conn.Close();