I am using command object in for loop on first time execution it inserts the record but the next time it gives an error
Multible OLEDB error
following is the code I use
Set rssave = New ADODB.Recordset
Set cmd = New ADODB.Command
'cmd.ActiveConnection = GCon
'cmd.CommandText = "prc_Invoice_Insert"
With mshFlexInvoiceEntry
fnOpenConnection
For i = 1 To .Rows - 1
tempindex = i
fnvalidate
fnSetNull
fntxtDate
' cmd.ActiveConnection = GCon
If .TextMatrix(i, 1) <> "" Or i = .Rows - 1 Then
tmp_Item = IIf(.TextMatrix(i, 1) = "", .Rows - 1, .TextMatrix(i, 1))
Cust_Addr = rchtxtCustAddress.Text
'sqlInsert = "Insert into Invoice (InvoiceNo,item,pono,dcno,invoicedate,podate,dcdate, custaddress,tinno,custservicetaxno,description,quantity,unitprice,amountTotal,kvat1,kvat2,cst1,cst2,servicetax) values ('" & txtInvoiceNo.Text & "','" & tmp_Item & "', '" & txtPONo.Text & "','" & txtDCNo.Text & "' , '" & Invoicedate & "','" & podate & "','" & DCDate & "','" & rchtxtCustAddress.Text & "' , '" & txtTinNo.Text & "','" & txtServiceTaxNo.Text & "','" & .TextMatrix(i, 2) & "', " & tempQTY & ", " & tempUNIT & "," & tempVALUE & "," & tempKVAT1 & "," & tempKVAT2 & "," & tempCST1 & "," & tempCST2 & "," & tempStax & ")"
'sqlInsert = "Insert into Invoice (InvoiceNo,pono,dcno,invoicedate,podate,dcdate, custaddress,tinno,custservicetaxno,description,quantity,unitprice,amountTotal,kvat1,kvat2,cst1,cst2,servicetax,subtotal) values (@invoicenum,@pono,@dcno,@invoicedt,@podt,@dcdt,@custadd,@tinno,@custservicetaxnum,@desc,@qty,@price,@totalamount,@kvat1,@kvat2,@cst1,@cst2,@servicetax,@subtotal)"
cmd.CommandText = "Insert into Invoice (InvoiceNo,pono,dcno,invoicedate,podate,dcdate, custaddress,tinno,custservicetaxno,description,quantity,unitprice,amountTotal,kvat1,kvat2,cst1,cst2,servicetax,subtotal) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
'cmd.CommandText = "prc_insert_invoice"
cmd.CommandType = adCmdTable
cmd.Parameters.Append cmd.CreateParameter("@invoicenum", adVarChar, adParamInput, 30, txtInvoiceNo.Text)
' cmd.Parameters.Append cmd.CreateParameter("@item", adInteger, adParamInput, tmp_Item)
cmd.Parameters.Append cmd.CreateParameter("@pono", adVarChar, adParamInput, 30, txtPONo.Text)
cmd.Parameters.Append cmd.CreateParameter("@dcno", adVarChar, adParamInput, 30, txtDCNo.Text)
cmd.Parameters.Append cmd.CreateParameter("@invoicedt", adDate, adParamInput, 10, Mid(Invoicedate, 1, 4) + "-" + Mid(Invoicedate, 6, 2) + "-" + Mid(Invoicedate, 9, 2))
cmd.Parameters.Append cmd.CreateParameter("@podt", adDate, adParamInput, 10, Mid(podate, 1, 4) + "-" + Mid(podate, 6, 2) + "-" + Mid(podate, 9, 2))
cmd.Parameters.Append cmd.CreateParameter("@dcdt", adDate, adParamInput, 10, Mid(DCDate, 1, 4) + "-" + Mid(DCDate, 6, 2) + "-" + Mid(DCDate, 9, 2))
cmd.Parameters.Append cmd.CreateParameter("@custadd", adVarChar, adParamInput, 250, rchtxtCustAddress.Text)
cmd.Parameters.Append cmd.CreateParameter("@tinno", adVarChar, adParamInput, 30, txtTinNo.Text)
cmd.Parameters.Append cmd.CreateParameter("@custservicetaxnum", adVarChar, adParamInput, 45, txtServiceTaxNo.Text)
cmd.Parameters.Append cmd.CreateParameter("@desc", adVarChar, adParamInput, 200, .TextMatrix(i, 2))
cmd.Parameters.Append cmd.CreateParameter("@qty", adDouble, adParamInput, tempQTY)
cmd.Parameters.Append cmd.CreateParameter("@price", adDouble, adParamInput, tempUNIT)
cmd.Parameters.Append cmd.CreateParameter("@totalamount", adDouble, adParamInput, tempVALUE)
cmd.Parameters.Append cmd.CreateParameter("@kvat1", adDouble, adParamInput, tempKVAT1)
cmd.Parameters.Append cmd.CreateParameter("@kvat2", adDouble, adParamInput, tempKVAT2)
cmd.Parameters.Append cmd.CreateParameter("@cst1", adDouble, adParamInput, tempCST1)
cmd.Parameters.Append cmd.CreateParameter("@cst2", adDouble, adParamInput, tempCST2)
cmd.Parameters.Append cmd.CreateParameter("@servicetax", adDouble, adParamInput, tempStax)
cmd.Parameters.Append cmd.CreateParameter("@subtotal", adDouble, adParamInput, tempSubtotal)
' Else
' sqlInsert = "update invoice set comments = '" & .TextMatrix(i, 2) & "' where invoiceno = " & txtInvoiceNo.Text & " and Item = " & tmp_Item & ""
End If
cmd.CommandType = adCmdText
cmd.Execute
cmd.CommandText = ""
Next
End With
fnCloseConnection
I look forward for suggessions