用SqlCommand对象
设置该对象的CommandText语句为查询语句,查询语句中指明查询的条件。
然后用SqlCommand对象的ExecuteScalar方法,判断方法返回的整数是否大于0,如果大于0表示,有对应的数据存在。
设置该对象的CommandText语句为查询语句,查询语句中指明查询的条件。
然后用SqlCommand对象的ExecuteScalar方法,判断方法返回的整数是否大于0,如果大于0表示,有对应的数据存在。
调试欢乐多
SqlConnection con = new SqlConnection(_ConString); try
{
//连接数据库中
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
con.Open(); cmd.CommandText = string.Format("select * from sysobjects where name='Income'");
SqlDataReader dr = cmd.ExecuteReader(); int a = 0;
while (dr.Read())
{
a = 1;
}
dr.Close(); if (a == 1)
{
cmd.CommandText = string.Format("drop table Income");
cmd.ExecuteNonQuery();
}
conn.Open();
OleDbCommand command = conn.CreateCommand();
string txtUSID = this.tbUserID.Text.Trim();
command.CommandText = "SELECT UserPass FROM UserInform WHERE UserID='" + txtUSID + "'";
OleDbDataAdapter DS = new OleDbDataAdapter(command);
DataTable DT = new DataTable();
DS.Fill(DT);
if (0 != DT.Rows.Count)
{
MessageBox.Show("该用户名已注册!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
tbUserID.Focus();
}