C#中带参数的select语句写法

来源:百度知道 编辑:UC知道 时间:2024/07/02 17:47:12
combobx1.text //存放姓名,年龄等
combobx2.text //存放<,>,!=
text1.text //用户输入的值
test //表名
"select * from test where ""+ combobx1.text+""+ combobx2.text+""+ text1.text.Trim()+""
是这样写吗?
sqlcom.Parameters.Add("@id", SqlDbType.bigint).Value
这语句我都不懂,不知道怎么弄,请问哪里有这方面资料看看吗?

推荐使用这样的方法
select * from table where id=@id
sqlcom.Parameters.Add("@id", SqlDbType.bigint).Value = 值;

select * from table where id=@id
sqlcom.Parameters.AddWithValue("@id", txt1.Text.Trim());
我习惯用这个,好懂,前面那个是参数,后面那个是参数的值

同意楼上,用这个比较好:
select * from table where id=@id
sqlcom.Parameters.Add("@id", SqlDbType.bigint).Value = 值;

如果按照一楼的作法,参数很多的情况下,sql语句就累死你,很容易出错.

"select * from test where ""+ combobx1.text+""+ combobx2.text+""+ text1.text.Trim()+""
其实比较方便,但是有sql注入的危险。

资料在msdn,不会不知道吧?

select * from table where id=@id
sqlcom.Parameters.Add("@id", SqlDbType.bigint).Value = 值;
这个应该算是一个标准的方法

select * from test where 字段A = '"+text1.text.Trim()+"'