Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Data.SqlClient.SqlException' occurred in system.data.dll

Status
Not open for further replies.

davepruce

Programmer
Dec 18, 2001
17
0
0
GB
I'm taking input from a VB.net proggie that I'm developing,
and trying to write the resulting 'record' to an SQL database table.
Can anyone help with a solution please?
Here's the complete error
-------------------------------------------------------
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.
-------------------------------------------------------
I get the error when the following code is executed at the last line:
-------------------------------------------------------
New_Return.add(Receipt_Date.Value)
New_Return.add(Dealer_Code.text)
New_Return.add(Customer_Code.text)
New_Return.add(Customer_PartNo.text)
New_Return.add(Quantity_Recd.text)
New_Return.add(Our_PartNo.text)
New_Return.add(Manuf_Date.Value)
New_Return.add(InService_Date.Value)
New_Return.add(Failure_Date.Value)
New_Return.add(Failure_Code.Text)
New_Return.add(Mileage.text)
'Now write it to the table
Dim WriteItConn As New SqlConnection("Integrated Security=SSPI;Data Source=****;" _
&"Initial Catalog=Customer_Returns")
WriteItConn.Open()
Dim WriteItNow As new SqlCommand("INSERT INTO [Returned_Items] " _
&"([Receipt_Date], [Dealer_Code], [Customer_Code], [Customer_PartNo], [Quantity_Recd], " _
&"[Our_PartNo], [Manuf_Date], [InService_Date], [Failure_Date], [FailureCode], [Mileage])" _
&"VALUES ('"&New_Return(1)&"', '"&New_Return(2)&"', '"&New_Return(3)&"', '"&New_Return(4)&"', " _
&"'"&New_Return(5)&"', '"&New_Return(6)&"', '"&New_Return(7)&"', '"&New_Return(8)&"', " _
&"'"&New_Return(9)&"', '"&New_Return(10)&"', '"&New_Return(11)&"'", WriteItConn)
WriteItNow.ExecuteNonQuery()
-------------------------------------------------
If I take out the ", WriteItConn" on the end of the Insert command, I get this error:
-------------------------------------------------
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

Additional information: ExecuteNonQuery: Connection property has not been initialized.
--------------------------------------------------
Any and all suggestions and help is apreciated
Sorry I've taken so much space!
Cheers
Dave
 
The first thing you want to do is to put a try catch block around the code so that it will catch the SQL Error

Try

'Put your code here

Catch ex as SQLClient.SQLException

Messagebox.show(ex.tostring)

End Try

This will give a an error message that is eaiser to understand. It is usually just a syntax error. Post what you get from the catch above.



DotNetDoc
M.C.S.D.
---------------------------------------

Tell me and I forget. Show me and I remember. Involve me and I understand.
- Anonymous Chinese Proverb
-----------------------------------
If you can't explain it simply, you don't understand it well enough.
- A. Einstein
 
Thanks DotNetDoc, should have thought of that myself - its solved the problem, yes it was syntax - duh
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top