Error in Adding New Record

  • Hello Everyone,

    Im new user of VB.net and I have a problem. I tried to append new record in the author's database but an error always occured in the sqldataadapter1.update. The error is something like

    An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

    Additional information: System error.

    If I modified certain records there's no error and the database is being updated with the new one. Pls help me fix my problem:

    Private Sub UpdateDataSet()

        Dim s As DataSet = New DataSet

        Me.BindingContext(DataSet11, "authors").EndCurrentEdit()

        s =

    CType(DataSet11.GetChanges, DataSet)

        If (Not (s) Is Nothing) Then

             Me.UpdateDataSource(s)

             DataSet11.Merge(s)

             DataSet11.AcceptChanges()

        End If

    End Sub

    Private Sub UpdateDataSource(ByVal c As DataSet)

         If (Not (c) Is Nothing) Then

             Me.SqlConnection2.Open()

             SqlDataAdapter1.Update(c)

             Me.SqlConnection2.Close()

         End If

    End Sub

  • At what point do you get the error?

     

    --------------------
    Colt 45 - the original point and click interface

  • Sir,

    Thank you for your response.

    when i tried to append a new record using the AddNew Method that's when i encounter an error.

  • Well that would explain it. I can't see any AddNew method in the code you've posted.

    Maybe you need to give a bit more relevant information so you can get a helpful reply.

     

    --------------------
    Colt 45 - the original point and click interface

  • Private

    Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

          Me.BindingContext(DataSet11, "authors").EndCurrentEdit()

          Me.BindingContext(DataSet11, "authors").AddNew()

          d =

    True

    End Sub

    Sir, thank you for your patience.

    Here is the button that appends a blank record at the author's database.

    As i have mentioned, when i clicked this button to add a new record, a blank line is created and i put some data, however, when i click the update button that calls the UpdateDataSet()an error occurs at the Sqldataadapter1.update(c) in  UpdateDataSource().

    Thank you again...

  • Ok, so do you know about exception handling in .Net? Do you know how to get the text of the error message?

     

    --------------------
    Colt 45 - the original point and click interface

  • hi sir,

    not yet sir i've just started the .net

    thank you.

     

  • Ok, then before you come to a SQL Server forum to get help about an error, how about you visit a VB.Net forum to get help about how to use .Net?

    Try any one of these and they should be able to help.

    http://www.vbforums.com/

    http://www.visualbasicforum.com/

    http://www.tek-tips.com/threadminder.cfm?pid=796

    http://www.eggheadcafe.com/forums/forumtree.asp?ID=14

    http://www.programmingtutorials.com/Forum.aspx?fid=5

     

     

    --------------------
    Colt 45 - the original point and click interface

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply