
查询出来,看返回的值:
例如:
select count() from Table where name='aa' and pwd = 'aa'
查出来后,看得到的值是否>0,如果>0,就说明有数据,否就是没有数据。
使用子查询可以分页
select top 1000 from 表 where 主键 not in
(select top (页码1000) 主键 from 表 )
第一个号代表所有,
第二个号代表乘以
首先C#连接Sql的方式有很多,我说一下我经常使用比较好理解的方法:
C#连接Sql的步骤:
①:添加引用using SystemDataSqlClient;
②:创建连接字符串;
③:创建SQL执行语句;
③:创建SqlConnection对象;
④:打开连接;
⑤:创建SqlCommand对象;
⑥:关闭连接;
-----------------------------------下面是增加记录的代码----------------------------------
string ConnString = "Data Source=SAWYER-PC;Initial Catalog=InfoDemo;Persist Security Info=True;User ID=sa;Password=123"; //创建连接字符串;
string SQL = "insert into Employee values('" + textBox1Text + "','" + textBox2Text + "','" + comboBox_SexSelectedItemToString() + "','" + dateTimePicker1ValueDateToString() + "','" + dateTimePicker2ValueDateToString() + "','" + comboBox_EdBSelectedItemToString() + "','" + comboBox1SelectedValueToString() + "','" + comboBox7SelectedValueToString() + "','" + comboBox4SelectedValueToString() + "')";//创建SQL执行语句,根据你程序的实际情况;
SqlConnection Conn = new SqlConnection(ConnString);//创建SqlConnection对象;
ConnOpen();//打开连接;
SqlCommand cmd = new SqlCommand(SQL, Conn);创建SqlCommand对象;
cmdExecuteNonQuery();
ConnClose();//关闭连接
----------------------查询,并将查询的结果绑定到 dataGridView1经行显示-------------------------
string ConnString = "Data Source=SAWYER-PC;Initial Catalog=InfoDemo;Persist Security Info=True;User ID=sa;Password=123";
SqlConnection Connection;
SqlDataAdapter Adapter;
string SQL = "select from Employee";
Connection = new SqlConnection(ConnString);
ConnectionOpen();
Adapter = new SqlDataAdapter(SQL, Connection);
DataSet data = new DataSet();
AdapterFill(data);
if (dataTablesCount > 0)
{
dataGridView1DataSource = dataTables[0];
}
ConnectionClose();
connOpen();
try
{
if(cmdExecuteNonQuery()==1)
MessageBoxShow("成功查找!", "信息提示");
else
MessageBoxShow("没有要你查找账户信息!请先核实账户信息 !", "信息提示");
}
catch(sqlException)
{
MessageBoxShow("没有要你查找账户信息!请先核实账户信息 !", "信息提示");
}
finally
{
MessageBoxShow("没有要你查找账户信息!请先核实账户信息 !", "信息提示");
connClose();
}
要大写,C#是区分大小写的
catch(SqlException)
OK啦
-----------------
第二次修改:
把finaplly里面的MessageBox去掉。就实现你想要的
finally
{
connClose();
}
以上就是关于c#.net winform怎么判断查询的数据在数据库中是否存在全部的内容,包括:c#.net winform怎么判断查询的数据在数据库中是否存在、C#winform如何实现数据库查询并分页、winform,用c#链接 sql server。对数据库进行查询记录,增加记录,删除记录。,修改记录。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)