Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!!!!!!!!!!!!!!

  • Moderators
Posted

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.

Visit...Bassic Software
Posted

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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...