|
发表于 2020-2-15 08:45:01
|
显示全部楼层
SqlConnection conn =null;
SqlCommand cmd = null;
DataSet ds = new DataSet();
string strConnectionString = "Data Source=.;initial catalog=数据库;uid=sa;pwd=xxx";
string strSQL = "SELECT 1 from 表 where 字段= 'aa'"
try
{
conn = new SqlConnection(strConnectionString);
conn.Open();
cmd = new SqlCommand(strSQL,conn);
if (cmd.ExecuteScalar() == null)
{
//不存在
}else
{
//存在.
}
}
catch(System.Exception e)
{
this.Text1.Text = "错误"+e.Message;
}
finally
{
if(conn!=null)
conn.Dispose();
if(cmd!=null)
cmd.Dispose();
}
|
|