怎样判断ACCESS数据库中存在某条记录?
先谢谢拉 !!!!!!!!
怎样判断ACCESS数据库中存在某条记录?
先谢谢拉 !!!!!!!!
[CODE]string sqlstr = "select count(*) from table1 where name='aaa'"; //查询table1表中是否有name为aaa的数据
SqlConnection myconn = new .............
SqlDataAdaper da = new SqlDataAdapter(sqlstr,myconn);
DataSet ds = new DataSet();
da.Fill(ds);
if(ds.Tables[0].Rows.Count > 0 )
{
//存在数据
}
else
{
//不存在数据
}[/CODE]
SqlConnection conn = new SqlConnection("server=.;database=myFirstPorject;uid=sa;pwd=sa");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from login where username='"+TextBox1.Text+"'and pwd='"+TextBox2.Text+"'", conn);
SqlDataReader odr = cmd.ExecuteReader();
if (odr.Read())
{
TextBox2.Text = "登录成功";
}
else
TextBox2.Text = "密码错误";
conn.Close();