各位好!
我用C#+SQL SERVER做了个产品系统
现在要判断某记录是否存在,如果存在则提示;该如何实现啊?
判断的字段是ProductId,buyer
变量为ID,username
如果记录中存在productid=ID and buyer=username
则表示已存在。用C#怎么写啊?请大侠们详细指点一下,谢谢!
我用C#+SQL SERVER做了个产品系统
现在要判断某记录是否存在,如果存在则提示;该如何实现啊?
判断的字段是ProductId,buyer
变量为ID,username
如果记录中存在productid=ID and buyer=username
则表示已存在。用C#怎么写啊?请大侠们详细指点一下,谢谢!
解决方案 »
- 100分求助css样式
- 如何经过后台处理 让清晰的图片变得模糊
- 【ASP.NET特效】为动态创建的表格添加鼠标事件
- 本地做的网站上传图片可以,但是放到服务器上,就不能上传图片,是什么原因,急
- 在showModalDialog打开窗口中可以再用showModalDialog打开其它窗口吗?
- 急求地区之间的二级级联的错误解决
- 求正则表达式:1)由汉字、英文字母(不区分大小写)或下划线组成,且必须以英文或汉字开头
- vs2005,找不到Web.Config!!用过的朋友指点!
- 用asp.net的日历控件怎么选取一周,而且怎么获取一周的日期值?
- dataGrid嵌套datagrid的显示与隐藏的问题(******)
- 进销存及帐务系统的设计问题
- 动态生成TEXTBOX
可以给个样例代码吗?非常感谢!
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString"].ConnectionString);
// Connect to the SQL database using a SQL SELECT query
// 变量为ID,username把下面sql改成变量
SqlDataAdapter cmd= new SqlDataAdapter("select count(*) from tb_goods where productid=ID and buyer=username ", conn);
//两种方法
int RecordCount=(Int32)cmd.ExecuteScalar()
//或者 SqlDataReader dr = new SqlDataReader();
// dr.read();
// int RecordCount=dr(0).ToString();
int i=cmd.scarlar()
if(i>0)
{存在}
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString"].ConnectionString);
SqlCommand cmd= new SqlCommand ("select count(*) from tb_goods where productid=ID and buyer=username ", conn);
int RecordCount=(Int32)cmd.ExecuteScalar()