string connStr = "server=localhost;uid=sa;pwd=sa;database=book";
SqlConnection myConnection = new SqlConnection(connStr);
string bookName = TextBox1.Text;
string queryStr = "SELECT * FROM [book_scheck] WHERE ([bookname] LIKE '%" + bookName + "%')";
SqlDataAdapter myDataAdapter = new SqlDataAdapter(queryStr, myConnection);
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet, "books");
if (myDataSet.Tables["books"].Rows.Count > 0)
{
Label1.Text = "所有图书:";
GridView1.DataSource = myDataSet.Tables["books"].DefaultView;
GridView1.DataBind();
}
else
{
Label1.Text = "没有图书登记!";
}
不行啊