select * from 表 where 字段='"+条件+"';
string SqlConn=System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn=new SqlConnection(SqlConn);
Conn.Open();
string mysql="select * from db_hetongguanli_y_g";
SqlCommand cm=new SqlCommand (mysql,Conn);
SqlDataReader dr=cm.ExecuteReader ();
while(dr.Read ())
{
if(!this.IsPostBack)
{
this.DropDownList2.Items.Add(new ListItem(dr["hetongid"].ToString()));
}
}
Conn.Close ();
dr.Close();
给一个最简单的!
cmd就是SqlCommand
if (cmd.ExecuteReader())
{
//有
}
else
{
//没有
}
从该表读数据,存入集合,然后判断集合是否为空
前面定义查询语句,创建Command对象,打开数据连接我就不讲了,太多
根据返回值咯
int count=Convert.ToInt32(cmd.ExcuteScalar);//cmd为Sqlcommand对象
if (count>0)
{
//有,给出提示
}else
{
//无,给无提示
}