我有以下代码,但我在参数方面遇到了困难......我收到以下错误:
sqlparametercollection 只接受非空的 sqlparameter 类型对象而不是 sqlparameter[] 对象
当我插入一个 msgbox 来检查param(0).value
我以 MARC 为例的值时。
我也应该为每个参数创建一个参数rowData.item(i)
吗?
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=USER\SQLEXPRESS;Initial Catalog=DBName;Integrated Security=SSPI"
con.Open()
cmd.Connection = con
Try
Dim InsertCommand As New SqlCommand
Dim param(0) As SqlClient.SqlParameter
param(0) = New SqlParameter("abrev", SqlDbType.VarChar, 50)
param(0).Value = UCase(abrev)
InsertCommand.Parameters.Add(param)
cmd.CommandText = "INSERT INTO allData (ABRV, Times, Num1, Num2, Num3, Num4, Num5) VALUES (param,rowData.Item(0),rowData.Item(1),rowData.Item(2),rowData.Item(3),rowData.Item(4),rowData.Item(5))"
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
Finally
con.Close()
End Try