C#查询语句
发布网友
发布时间:2022-04-19 13:01
我来回答
共2个回答
热心网友
时间:2023-08-31 03:56
//控件够了已不用再拉
string str="server=localhost;uid=sa;pwd=sa;database=mysql";
string source="select * from Book where BookID="+this.textBox1.Text;
SqlConnection conn=new SqlConnection(str);
SqlDataAdapter sqlDataAdapter1=new SqlDataAdapter(conn,sourec);//实例化一个DataAdapter
DataSet objDataSet1=new DataSet();//实例化一个DataSet
sqlDataAdapter1.Fill(objDataSet1,"Book");//把符合条件的数据填充到DataSet.
if(objDataSet1.Table["Book"].Rew.Count!=0)//判断DataSet里有无记录
this.dataGrid1.DataSource=objDataSet1.Table["Book"];
else
MessageBox.Show("输入有误");
//要记得using Syatem.Data.SqlClient;sqlDataAdapter1和objDataSet1可以在类一级下声明
热心网友
时间:2023-08-31 03:57
//鎺т欢澶熶简宸蹭笉鐢ㄥ啀鎷�
string str="server=localhost;uid=sa;pwd=sa;database=mysql";
string source="select * from Book where BookID="+this.textBox1.Text;
SqlConnection conn=new SqlConnection(str);
SqlDataAdapter sqlDataAdapter1=new SqlDataAdapter(conn,sourec);//瀹炰緥鍖栦竴涓狣ataAdapter
DataSet objDataSet1=new DataSet();//瀹炰緥鍖栦竴涓狣ataSet
sqlDataAdapter1.Fill(objDataSet1,"Book");//鎶婄�鍚堟浔浠剁殑鏁版嵁濉�厖鍒瘅ataSet.
if(objDataSet1.Table["Book"].Rew.Count!=0)//鍒ゆ柇DataSet阅屾湁镞犺�褰�
this.dataGrid1.DataSource=objDataSet1.Table["Book"];
else
MessageBox.Show("杈揿叆链夎�");
鎴戝皢涓婇溃镄勯偅浣崭唬镰佺矘璐翠简涓嬫潵锛屾垜璺熶粬链変竴镣瑰皬灏忕殑鍖哄埆灏辨槸
SqlDataAdapter sqlDataAdapter1=new SqlDataAdapter(conn,sourec);//瀹炰緥鍖栦竴涓狣ataAdapter
鍦ㄨ繖琛屼腑鎴戣�涓烘槸SqlDataAdapter sqlDataAdapter1=new SqlDataAdapter(sourec,conn);//瀹炰緥鍖栦竴涓狣ataAdapter