补充一下代码:
SqlConnection myconn = getconnection();
myconn.Open();
Label1.Text = "连接成功";
string sqlstr = "select * from news where name=@name";
SqlCommand mycmd = new SqlCommand(sqlstr, myconn);
mycmd.Parameters.Add("@name", SqlDbType.VarChar, 20).Value = this.txtname.Text.Trim();
SqlDataAdapter myda = new SqlDataAdapter(mycmd);
DataSet myds = new DataSet();
myda.Fill(myds);