public static userinfomodel GetUserByLoginId(userinfomodel user)
{
string sql = "select * from userinfo where user_id=@user_id";
SqlParameter[] values =
{
new SqlParameter("@user_id",user.User_id)
};
List<userinfomodel> list = new List<userinfomodel>();
if (list != null && list.Count > 0)
{
return list[0];
}
return null;
}这个方法是判断用户是否存在,好像方法不对
{
string sql = "select * from userinfo where user_id=@user_id";
SqlParameter[] values =
{
new SqlParameter("@user_id",user.User_id)
};
List<userinfomodel> list = new List<userinfomodel>();
if (list != null && list.Count > 0)
{
return list[0];
}
return null;
}这个方法是判断用户是否存在,好像方法不对
解决方案 »
- 正则表达式?
- DropDownList的事件问题
- 用JS获取客户端Mac地址的代码,怎样插进.Net里?
- 压抑!!
- 一个将string向JS的变量里赋值的问题----在线等.
- 多语言支持问题,高分送给高手!!!!!!!!
- 在开发asp.net打印word时遇到的问题,我在word里有个1列1000行表格,我要在每行插入一个书签,从num1~num100,怎么能方便的插入。一个一
- 要求熟练掌握Web Service ,那都要掌握什么内容?
- 应该是简单问题,求高手帮忙,100分相送,绝不食言,一下午都没弄出来,太灰心了.....
- 怎样将字符串中的双引号替换成单引号?
- 就是那个网站点击赞的那个功能,游客也可以实现,每隔30分钟可以点击一次的功能如何实现
- 为什么为什么?急救啊!怎么获取不到label的值啊
com.CommandText = "Select * from Users where UserName='" + tbUserName.Text + "'";
com.CommandType = CommandType.Text;
com.Connection = con;
bool flag = com.ExecuteScalar()==null?false:true;//ture 存在
{
bool b = false;
using (MySqlConnection con = new MySqlConnection(Connection))
{ MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = @"select * from userinfo where user_id=@user_id";
b= cmd.ExecuteScalar(CommandBehavior.CloseConnection);
if(b)
{
return b; }else
{
return b;
}
}
{
b = true;
}
else
{
return b;
}
当返回结果不是0的时候(为1吧),就说明存在了
con.Open();//打开连接
try
{
SqlCommand com = new SqlCommand();
com.CommandText = "Select count(*) from Users where UserName='" + tbUserName.Text + "'";
com.CommandType = CommandType.Text;
com.Connection = con;
object flag = com.ExecuteScalar();
if(flag!=null)
{
return Convert.toInt32(flag);
}
else
{
return -1;
}
}
catch()
{
}
finally
{
con.close();
}你最后可以返回一个整型,要是有用户存在,就会返回>0的数,不然的话就此用户就不存在
public static int GetUserByLoginId(userinfomodel user)
{
string sql = "select count(*) from userinfo where user_id=@user_id";
SqlConnection conn = new SqlConnection(DBHelper.connString);
conn.Open();
SqlCommand command = new SqlCommand(sql,conn);
int result =Convert.ToInt32(command.ExecuteScalar());
if (result > 0)
{
return -1;
}
else
{
return 1;
}
}我改成这样了,但是提示“必须声明标量变量@user_id”
cmd.Parameters.AddWithValue("@user_id",5);
话说、我建议你多看点学习视频之类的好好补习一下吧...