Problems with updating databases from a dataset in visual basic .net , sql , sql server express 2008 Ipswich, United Kingdom
  • 11 years ago

    I am writitng a program that uses a database as the backend and visual basic .net for the gui. I have created a table in the ms sql express that a user can pick from and record to. I can bind the information from the table to a combobox so the users can pick it. The problem is that any new data that is input into the dataset is not being saved back to the origional table in the database.

    This is my code so far:

    Dim cn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\StudentODPLogBook.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True") Dim cmd As New SqlCommand

        'insert SQL command'
        cmd.CommandText = "Insert Into OperationsTable (OperationName,OperationId) Values (@OperationName,5)"
        'Takes the text box data as the parameter to be stored in the dataset'
        cmd.Parameters.AddWithValue("@OperationName", TextBox4.Text)
        'Open connection ,execute sql command and close connection'
        'cmdBuilder = New SqlCommandBuilder(SqlDataAdapter1)
        cmd.Connection = cn
        'if problem with connection on insertion exception caught a relayed to user
        MsgBox("Inserted " + TextBox4.Text) ' shows succesful insertion of data into dataset'
        'refils adapter with new data from dataset'

    Iam using the SqlDataAdapter.update method to try and update the database, but it does not seem to be working.

    Can anyone please help or point me in the right direction.


Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There's no test like production” - Anon