public int CheckName()
{
try
{
SqlConnection conn = new SqlConnection("Data Source=DC-BOY;Initial Catalog=MyData;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("SELECT UserName FROM [MyData].[dbo].[User] WHERE UserName='"+this.username.Text+"'", conn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
DataTable tb = ds.Tables[0];
if(tb.Rows[0]["UserName"].ToString()!= "0")
{
return -1;//用户存在
}
}
return 2;//用户名不存在
}
catch(Exception ee)
{
return 0;//查找失败
}
}
asp.net C# Sql 查找用户是否存在
最新推荐文章于 2022-07-26 14:06:55 发布