积极答复者
vb.net2010 参数化查询

问题
-
dim time as date=now
dim b as integer=1,c as integer=2,d as integer=3,e as integer=4,f as integer=5,g as string="string"
……
MyOledbCommand.CommandText = "Insert Into tablename " _
& "(时间,编号,col3,col4,col5,col6,col6) " _
& "Values (" _
& "'" & time & "', " _
& "'" & b & "', " _
& "'" & c & "', " _
& "'" & d & "', " _
& "'" & e & "', " _
& "'" & f & "', " _
& "'" & g & "')"……
请教上述查询语句如何修改成参数化查询语句
答案
-
Using cmd As New OleDbCommand("Insert into xxx(Field1,Field2,....,FieldN)values(@1,@2...,@N)",New OleDBConnection("Conn Str")) cmd.Parameters.AddWithValue("@1",Your Real Value) ……………… cmd.Connection.Open() cmd.ExecuteNonQuery() End Using
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats- 已建议为答案 Chester HongModerator 2013年4月15日 2:04
- 取消建议作为答案 小小芝麻开门 2013年4月19日 12:24
- 已标记为答案 小小芝麻开门 2013年4月19日 14:36
全部回复
-
Using cmd As New OleDbCommand("Insert into xxx(Field1,Field2,....,FieldN)values(@1,@2...,@N)",New OleDBConnection("Conn Str")) cmd.Parameters.AddWithValue("@1",Your Real Value) ……………… cmd.Connection.Open() cmd.ExecuteNonQuery() End Using
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats- 已建议为答案 Chester HongModerator 2013年4月15日 2:04
- 取消建议作为答案 小小芝麻开门 2013年4月19日 12:24
- 已标记为答案 小小芝麻开门 2013年4月19日 14:36