八爪钩怎么使用图解:C#查询语句

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/10 08:25:50
我是C#新手。请高手帮我看下代码,我想实现的功能是:
只有一 Textbox 和一个 Butten 控件
通过在Textbox输入BookID 然后按Butten查询
自己随便写的代码 但老是提示objDataSet1没定义,请高手指点,谢谢
代码如下:
string source="select * from Book where BookID="+this.textBox1.Text;
this.sqlDataAdapter1.SelectCommand.CommandType=CommandType.Text;
this.sqlDataAdapter1.SelectCommand.CommandText=source;
this.sqlDataAdapter1.SelectCommand.Connection=this.sqlConnection1;
this.sqlDataAdapter1.Fill(this.objDataSet1,"Book") dataGrid1.DataSource=this.objDataSet1;
this.dataGrid1.DataMember="Book";
dataGrid1.Refresh();
可以的话请帮我写上完整的代码 能直接运行的(就是不用再拉控件的那种)初学问题很多
回答者将追加分数 谢谢

string sqlStr = "Select * from [Book]";
SqlConnection myConnection = new SqlConnection("连接字符串");
SqlCommand command = new SqlCommand(sqlStr, myConnection);
SqlDataAdapter myAdapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
myAdapter.Fill(ds);
后面的就不用再说了吧