alleho Posted January 29, 2004 Posted January 29, 2004 Help this is driving me mad. I have a .net app. that used Visual FP8 as a back end. On a form I have 6 fields that need to be inserted to a datatable. I wrote this code but everytime I run it i get: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll Unhandled Exception: System.Data.OleDb.OleDbException: Variable 'ECASSTR' is not found. Dim ecasstr As Integer Dim descstr As String Dim productid As Integer Dim producttypeid As Integer Dim brandid As Integer Dim codetypeid As Integer Dim Cmmtrans As New OleDb.OleDbCommand Dim Tranin As OleDb.OleDbTransaction Dim CnnUserman As OleDb.OleDbConnection 'get values from current record ecasstr = Me.txtECAS.Text descstr = Me.txtDescription.Text productid = Me.CboProduct.SelectedValue producttypeid = Me.CboProductType.SelectedValue brandid = Me.cboBrand.SelectedValue codetypeid = Me.CboCodeType.SelectedValue CnnUserman = OleDbConnection1 CnnUserman.Open() Cmmtrans.Connection = CnnUserman Tranin = CnnUserman.BeginTransaction() MessageBox.Show(ecasstr) Cmmtrans.CommandText = "INSERT INTO tblstock (ecas, description, productid, producttypeid, brandid, codetypeid) " & _ "VALUES(ecasstr,descstr,productid,producttypeid,brandid,codetypeid)" Cmmtrans.Transaction = Tranin Cmmtrans.ExecuteNonQuery() Tranin.Commit() CnnUserman.Close() I added the msgbox to check that I was getting the right data; I am. I have changed the variable to accultual text and numbers and it insets OK. Please Help!!!!!!!!!!!!!! Quote
Moderators Robby Posted January 29, 2004 Moderators Posted January 29, 2004 try this ... Cmmtrans.CommandText = "INSERT INTO tblstock (ecas, description, productid, producttypeid, brandid, codetypeid) " & _ "VALUES('" & ecasstr & "', '" & descstr & "', " _ & productid & " , " & producttypeid & " , " & brandid & " , " & codetypeid & ")" I didn't double-check if the vars were String Or Integer. If the data type is string in the DB then surround the var with single quotes, for numeric types don't. Quote Visit...Bassic Software
alleho Posted February 2, 2004 Author Posted February 2, 2004 Dates Is there anything different I have to do with date fields? I have tried with and with out quotes but I'm getting. Data type mismatch. Any help greatly received... Quote
Moderators Robby Posted February 2, 2004 Moderators Posted February 2, 2004 For Access db replace the single quotes with the pound (#) sign. Quote Visit...Bassic Software
alleho Posted February 2, 2004 Author Posted February 2, 2004 If only it were. I have to use Foxpro, tried the old access trick!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.