如何实现 查数据库,看是否已经存在 想要输入的 数据 请兄弟们给完整的代码
解决方案 »
- WinForm项目打包微软报表出错
- C# 编写的视频或者音频播放器,什么控件适合做播放进度或者音量调节啊?
- 关于用toolTip1.SetToolTip()设置一直显示的问题
- 怎么把时间2007-06-01 转换成20070601
- 如何在C#的菜單中加入圖片?
- 关于treeview问题,大家帮忙
- 怎么截取路径呢?
- 高分跪求:webClient DownloadFile 如何突破Proxy?
- 还是留言板中的问题,请各位asp.net的高手帮帮我(查看和回复留言)
- 在C #中如何执行多条sql语句
- 众位大哥大姐救命啊!C# TCP/IP问题,先谢谢啦!
- 网页在IE下会假死几秒钟,其他浏览器都没问题
SqlConnection conn = new SqlConnection(xxxxxxxx);
conn.Open();
SqlCommand cmd = new SqlCommand(@"SELECT COUNT(*) FROM tabname where username=@username , conn);
cmd.Parameters.Add(new SqlParameter("@username", UserName));
int i = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
if (i > 0)
{
//存在
SqlConnection conn = new SqlConnection(xxxxxxxx);
conn.Open();
SqlCommand cmd = new SqlCommand(@"SELECT COUNT(*) FROM tabname where username=@username , conn);
cmd.Parameters.Add(new SqlParameter("@username", UserName));
int i = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
if (i > 0)
{
//存在
}
=======
SELECT 1 FROM tabname where username=@username1.我觉得 没必要用count函数
2.用1代替* 效率上会有很大提升
select * from XX
if()
else
{
}
public static bool panduan(string userName)
{
SqlConnection con = ljm.createCon();
con.Open();
SqlCommand cmd =new SqlCommand("select count(*) from xinxi where 用户名='" + userName + "'", con);
int i = (int)cmd.ExecuteScalar();
con.Close();
if (i > 0)
return true;
else
return false;
}