commandtext in executenonquery
Public Function CreateInsertCommand() As SqlCommand
Dim strsql As String
strsql = "INSERT INTO MCS_CURRENT ( COMPANYCODE , EMPLOYEENO , COSTCENTER , LEADID , WORKSCHEDULEDATE , JOBNO , OPERATION , LINEHOURS , DATEIN, TIMEIN , DATEOUT , TIMEOUT ,ETCIN , ETCOUT , EQUIPMENTNO , UPDATETIME ) VALUES ( ? ,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "
Dim CMD As New SqlCommand(strsql, MyConnection)
Dim PC As SqlParameterCollection = CMD.Parameters
PC.Add("COMPANYCODE_NEW", SqlDbType.Int)
PC.Add("EMPLOYEENO_NEW", SqlDbType.BigInt)
PC.Add("COSTCENTER_NEW", SqlDbType.BigInt)
....
.....
PC.Add("UPDATETIME_NEW", SqlDbType.DateTime)
Return CMD
End function
Public Function submitInsert(ByVal row As DataRow, ByVal cmd As SqlCommand) As Integer
Dim PC As SqlParameterCollection = cmd.Parameters
PC("COMPANYCODE_NEW").Value = row("COMPANYCODE")
Console.WriteLine(row("COMPANYCODE"))
PC("EMPLOYEENO_NEW").Value = row("EMPLOYEENO")
...
....
PC("EQUIPMENTNO_NEW").Value = row("EQUIPMENTNO")
PC("UPDATETIME_NEW").Value = row("UPDATETIME")
Console.WriteLine(cmd.CommandText)
Return cmd.ExecuteNonQuery()
End Function
When I run this I get an error at the line Return cmd.ExecuteNonQuery() .
It could be a syntax error but when I console.writeline cmd.Commandtext it gives me the text like
INSERT INTO MCS_CURRENT ( COMPANYCODE , EMPLOYEENO , COSTCENTER , LEADID , WORKSCHEDULEDATE , JOBNO , OPERATION , LINEHOURS , DATEIN, TIMEIN , DATEOUT , TIMEOUT ,ETCIN , ETCOUT , EQUIPMENTNO , UPDATETIME ) VALUES ( ? ,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
and not with the actual values of ? s so that I can run it on the sql query analyser and debug.
How do I get the commndtext with all the passed parameters values.I do see all the parametercollection getting populated in my submitInsert function above. But it doesnt show up in the command text.
Please help
thx

