sidwelle
asked on
Why don't my params populate ?
Trying to get an update with param to work, trying to populate a field with a string of text about 1k. I don't get an error, fields just don't populate.
Dim cmd As New OleDb.OleDbCommand
'VarChar DECLARE @msg VarChar
'cmd.Parameters.AddWithValue("@msg", Msg)
'**** This works, but I don't want to worrry about ' and "
'cmd.CommandText = _
' "DECLARE @msg VarChar " & _
' "UPDATE tblMsgs01 " & _
' "SET msg = '" & Msg & "' " & _
' "WHERE id = '" & sID & "'"
'**** this does not work and I have to 'DECLARE @msg ...' or the SQL conn complains, ("You must declare scaler variable ...")
cmd.CommandText = _
"DECLARE @msg VarChar " & _
"UPDATE tblMsgs01 " & _
"SET msg = @msg " & _
"WHERE id = '" & sID & "'"
'*** Try 1, failed
cmd.Parameters.Add("@msg", OleDb.OleDbType.VarChar)
cmd.Parameters("@msg").Value = "test"
'*** Try 2, failed
'Dim param As New OleDb.OleDbParameter
'param.Value = Msg
'cmd.Parameters.AddWithValue("@msg", param)
'*** Try 3, failed
'cmd.Parameters.Add("@Msg", OleDb.OleDbType.VarChar)
'cmd.Parameters("@Msg", msg)
'*** Try 4, failed
'cmd.Parameters.AddWithValue("@msg", msg)
cmd.ExecuteNonQuery()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What kind of database are you connecting to?
ASKER
MS SQL 2005 Enterprize.
The classes found under the System.Data.SqlClient namespace are typically used to connect to MS SQL. The SqlCommand class does allow named parameters.
ASKER
I switch the project over to using SqlCommand class. had to remove "Provider=SQLOLEDB" from the conn string.
ASKER
Is there a connection that would be better suited to what I am doing than OleDb ?