如果是在后台存储过程中,可以用以下方法判断: if not exists(select 1 from tablename where user_id=@userid) begin --不存在 end else begin --存在 end如果在前台,可以用以下语句返回一个表: select count(*) from tablename where user_id=用户名然后根据该表的第0行第0列的数值判断: if (convert.toint32(dt.rows[0][0])==0) { //不存在 } else { //存在 }
string sqlstr = "select *from link where ConnID='" + this.Txt_ID.Text + "'"; SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count < 1) { }
public int Login(string sql) { string str = "server=.;database=pubs;integrated security=SSPI"; SqlConnection con = new SqlConnection(str); con.Open(); SqlCommand cmd = new SqlCommand(sql,con); int count = Convert.ToInt32(cmd.ExecuteScalar()); return count; } string sql="select *from link where ConnID= '" + this.Txt_ID.Text + " '"; int i=cla.Login(sql); if (i > 0) {
if not exists(select 1 from tablename where user_id=@userid)
begin
--不存在
end
else
begin
--存在
end如果在前台,可以用以下语句返回一个表:
select count(*) from tablename where user_id=用户名然后根据该表的第0行第0列的数值判断:
if (convert.toint32(dt.rows[0][0])==0)
{
//不存在
}
else
{
//存在
}
SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count < 1)
{
}
{
string str = "server=.;database=pubs;integrated security=SSPI";
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd = new SqlCommand(sql,con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
return count;
} string sql="select *from link where ConnID= '" + this.Txt_ID.Text + " '";
int i=cla.Login(sql);
if (i > 0)
{
}