[2005] manual DataAdapter failing
Code:
dim Insert as string="insert into acaps(AppId,activity_dt,activity_cd,process_state,UserId,SeqNbr,LocCode,comments) values (@AppId,@activity_dt,@activity_cd,@process_state,@UserId,@SeqNbr,@LocCode,@comments)"
Dim x As New Odbc.OdbcDataAdapter(selectQ.ToString, DirectCast(Me._Cn, Odbc.OdbcConnection))
If x.InsertCommand Is Nothing Then
x.InsertCommand = New Odbc.OdbcCommand(insert)
Else
x.InsertCommand.CommandText = insert
End If
x.InsertCommand.Connection = DirectCast(Me._Cn, Odbc.OdbcConnection)
x.InsertCommand.CommandTimeout = InsertTimeout
For index As Integer = 0 To ColList.Count - 1
Select Case srcData.Columns(index).DataType.FullName
Case "System.String"
x.InsertCommand.Parameters.Add(New Odbc.OdbcParameter("@" + ColList(index), System.Data.DbType.String))
Case "System.DateTime"
x.InsertCommand.Parameters.Add(New Odbc.OdbcParameter("@" + ColList(index), System.Data.DbType.Date))
Case Else
MsgBox(srcData.Columns(index).DataType.FullName)
Stop
End Select
x.InsertCommand.Parameters.Item("@" + ColList(index)).SourceColumn = ColList(index)
x.InsertCommand.Parameters.Item("@" + ColList(index)).SourceVersion = DataRowVersion.Current
'x.InsertCommand.Parameters.Add(New Odbc.OdbcParameter(ColList(index), srcData.Columns(index).GetType))
Next
'If rollbackOnException Then
' Me.TestMode = True
'End If
'Dim da As System.Data.Common.DataAdapter = Me.chDataAdapter(selectQ.ToString, Me._Cn)
For index As Integer = 0 To srcData.Rows.Count - 1
srcData.Rows(index).SetAdded()
Next
Fill = x.Update(srcData)
srcData.AcceptChanges()
The error is must declare the scalar Variable '@AppID'
I'm not practiced in using parameters but I'm trying to follow the example at:
http://msdn.microsoft.com/en-us/library/ms810297.aspx
And have been trying things, but haven't found how to get it fire. At run time when I look at the value of the @Appid paramter it has the first row's value so it doesn't appear to be that.
Re: [2005] manual DataAdapter failing
Does your INSERT statement have @AppID declared in it?
How did you come up with ColList()?
Re: [2005] manual DataAdapter failing
The insert statement is at the top of line of my post, which includes @AppId. ColList is obtained from walking each of the columns of the srcData dataTable and using the columnName. This process is only set to work if the srcData table column names match with column names on the fill side.
Also I've discovered:
When I convert to using SqlClient.SqlDataAdapter it works just fine, seems the odbc driver doesn't like @ placeholders. Maybe it wants '?'. I'll still need to figure this out for other systems because I need to talk to things besides sql server.
Re: [2005] manual DataAdapter failing
Ah, hadn't noticed that.
Are you using MySql? MySql is slightly weird in that it wants either ?columnname or simply columnname depending on your version.
You could alternatively just use standalone ? marks and then supply the parameters in the exact order as in the statement.