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!

How to access an SQL 2005 DB in VB.Net

Status
Not open for further replies.

ShawnCoutts

Programmer
Jul 4, 2006
74
CA
I am a relatively new user to VB.NET, but have worked extensively in VB 6. In my program, using the server explorer, I have created an sqlconnection object and a data adapter for each table in my database. The problem I am having comes when I try to use an insert command to insert a new record into my database. The syntax of my command is correct, but I continually get the following error:

System.Data.OleDb.OleDbException: Must declare the scalar variable "@MillCode".

Now this variable has been declared as I have made sure to add a parameter for each value being inserted. I have been working on this for the better part of a day, and am getting quite frustrated with the whole thing. Any help would be greatly appreciated.

Shawn
 
Hi you should check the stored procedure used for your insert statement.

 

Hi Shawn,

It sounds like you're using the data adapter's insert command. I've always found that to be a big frustrating pain. You can try using a CommandBuilder to make the insert statement for you. I have an unfounded mistrust of them in the final product so don't leave them in, but you can put a breakpoint and watch on it, step through and copy the insert command it generates and assign it to your data adapter's insert command.

Good luck,
Pat



 
Are you using the drag/drop objects on the form its self to perform database actions, with a DataGrid?

Also can you post the sql command, you can find this in the Properties window: DataAdapter.InsertCommand.CommandText?

Also I noticed, you are using a SqlConnection, but you have used OleDbDataAdapter, I think you do need to use the SqlDataAdapter for it to work properly anyway.

 
what I actually was using was the oledbConnection and the oledbDataAdapter and yes i was using the drag and drop components. I did manage to solve my problem. The oledbDataAdapter doesnt really like paramaters in its queries, so once i took out the paramaters and directly accessed the data i was trying to insert, everything worked out fine. Thanks to all for their help.

Shawn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top