Trying to insert?

  • Thread starter Thread starter Dan Keeley
  • Start date Start date
D

Dan Keeley

Hi,

I've got another problem now! Getting "Input string was not in a correct
format"

I have this as my insert command:

myDataAdapter.InsertCommand = connection.CreateCommand()
myDataAdapter.InsertCommand.CommandText = _
"Insert into Suppliers " & _
"(SupplierName, TechnicalContact, SalesContact, OperationsContact,
WorkPhone, FaxNumber" & _
" , Address, City, County, PostalCode, Email, MobilePhone) " & _
"values(&SupplierName, &TechnicalContact, &SalesContact, &OperationsContact,
&WorkPhone, &FaxNumber" & _
", &Address, &City, &County, &PostalCode, &Email, &MobilePhone )"
AddParms(myDataAdapter.InsertCommand, "SupplierName", "TechnicalContact",
"SalesContact", "OperationsContact" _
, "WorkPhone", "FaxNumber", "Address", "City", "County", "PostalCode",
"Email", "MobilePhone")
MsgBox(myDataAdapter.InsertCommand.CommandText)

Followed by:

Dim newRow As DataRow = myDataTable.NewRow()
newRow("SupplierName") = txtSupplierName.Text
newRow("TechnicalContact") = txtTechnicalContact.Text
newRow("SalesContact") = txtSalesContact.Text
newRow("OperationsContact") = txtOperationsContact.Text
newRow("WorkPhone") = txtPhone.Text
newRow("FaxNumber") = txtFax.Text
newRow("Address") = txtAddress.Text
newRow("City") = txtCity.Text
newRow("County") = txtCounty.Text
newRow("PostalCode") = txtPostalCode.Text
newRow("Email") = "BLAR"
newRow("MobilePhone") = txtPhone.Text


Then when i do this:

myDataTable.Rows.Add(newRow)
MsgBox(newRow.ItemArray.Length)
'Update the DB
Try
myDataAdapter.Update(myDataSet, "Suppliers")

I get the error.

Now I can't for the life of me find the problem. I'm not inserting anything
into my key field, but thats autonumber, so this shouldnt matter right?

How can i find the ACTUAL sql that it's having a problem with, I can't seem
to get to it in the debugger.

I've confirmed that the datatable and newrow have the same number of items,
which makes sense...

Any hints on either a fix, or just simply debugging this would be a massive
help! Thanks once again!

Rgds,
Dan
 
Dan Keeley said:
I've got another problem now! Getting "Input string was not in a
correct format"

I have this as my insert command:

myDataAdapter.InsertCommand = connection.CreateCommand()
myDataAdapter.InsertCommand.CommandText = _
"Insert into Suppliers " & _
"(SupplierName, TechnicalContact, SalesContact, OperationsContact,
WorkPhone, FaxNumber" & _
" , Address, City, County, PostalCode, Email, MobilePhone) " & _
"values(&SupplierName, &TechnicalContact, &SalesContact,
&OperationsContact, &WorkPhone, &FaxNumber" & _
", &Address, &City, &County, &PostalCode, &Email, &MobilePhone )"
AddParms(myDataAdapter.InsertCommand, "SupplierName",
"TechnicalContact", "SalesContact", "OperationsContact" _
, "WorkPhone", "FaxNumber", "Address", "City", "County",
"PostalCode", "Email", "MobilePhone")
MsgBox(myDataAdapter.InsertCommand.CommandText)


Why do you use the "&" char for parameters? I thought it's the "@".

More ADO.NET related questions:
microsoft.public.dotnet.framework.adonet
 
Why do you use the "&" char for parameters? I thought it's the "@".

Indeed it should be, so I changed that and still get the same message....

Maybe it's not even getting that far? Anyone any further hints on debugging
this?
 
Hi Dan,
Did you ever see SQLcommandbuilder or OleDBcommandbuilder, that makes every
thing a lot easier?
Cor
 
Cor said:
Hi Dan,
Did you ever see SQLcommandbuilder or OleDBcommandbuilder, that makes every
thing a lot easier?
Cor

Excellent that works and so much easier!!!

now why didnt oreilly spot that!!

Thanks very much
Dan
 
Dan Keeley said:
Excellent that works and so much easier!!!

now why didnt oreilly spot that!!

Before posting my first reply, I used your code to have the string built,
but I didn't see an error in the resulting SQL string. Did you find out why
the error occured meanwhile?
 
Before posting my first reply, I used your code to have the string built,
but I didn't see an error in the resulting SQL string. Did you find out why
the error occured meanwhile?


--
No, afraid not, Im still confused as to why it didnt work.
 
Back
Top