locked
DataGridview Update .. RRS feed

  • Question

  • Hi ,,

     

     

    I have a very small application ,, I am still learning vb.net ... so , in this application I have a database in sql express 2005 consist of one table called AccessPage,, i did everything and its working fine but when I changed somthing in the datagridview it look like its changed,,, but when I close the application or even the form and open againg i didnt see the changed I did ,, why ??

     

    Simply ... I dont know how to update table using datagridview ?? I want to create a save button in a datagridview without using wizards (pure code)...

     

     

    thanx in advane...

    Friday, January 25, 2008 11:38 PM

Answers

  •  alnahash wrote:

    in this application I have a database in sql express 2005 consist of one table called AccessPage,, i did everything and its working fine but when I changed somthing in the datagridview it look like its changed,,, but when I close the application or even the form and open againg i didnt see the changed I did ,, why ??

     

    Simply ... I dont know how to update table using datagridview ?? I want to create a save button in a datagridview without using wizards (pure code)...

     

    Hi alnahash,

     

    Code Snippet

    Imports System.Data.SqlClient

     

    Public Class Form1

        Dim myDA As SqlDataAdapter

        Dim myDataSet As DataSet

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Dim con As SqlConnection = New SqlConnection("Data Source=.;Integrated Security=True;AttachDbFilename=|DataDirectory|\SqlDatabase.mdf")

            Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM AccessPage", con)

            con.Open()

            myDA = New SqlDataAdapter(cmd)

            'Automatically generates DeleteCommand, UpdateCommand and InsertCommand for DataAdapter object

            Dim builder As SqlCommandBuilder = New SqlCommandBuilder(myDA)

     

            myDataSet = New DataSet()

            myDA.Fill(myDataSet, "MyTable")

            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

     

            con.Close()

            con = Nothing

        End Sub

       

        ' Save data from DataGridView into Database

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Me.Validate()

            Me.myDA.Update(Me.myDataSet.Tables("MyTable"))

            Me.myDataSet.AcceptChanges()

        End Sub

     

    End Class

     

     

    In addition:

    Select/click your database file in Solution Explorer

    -> Properties Pane

    -> change the "copy to ouput directory" to "copy if newer"

     

    This blog is beneficial to you.

    https://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx

     

    Tuesday, January 29, 2008 10:20 AM
  • I think you should look into VBEE 2008 and using LINQ and the LINQ to SQL classes . I'll give you an example of a project . This project has 3 tables with relationship keys where the CustomerID key in the Customer table is linked to the CustomerID key in the Orders table which has a key linking it to the OrderDetails table . The form has 3 DataGridViews to display the data .

     

    Public Class Form1

     

    Dim DB As New BDClasses1DataContext

     

    Private Sub CustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerBindingNavigatorSaveItem.Click

    Me.Validate()

    CustomerBindingSource.EndEdit()

    Try

    DB.SubmitChanges()

    MessageBox.Show("saved")

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    End Sub

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.CustomerBindingSource.DataSource = DB.Customers

    End Sub

    End Class

     

    You see there is very little code involved and you can still use LINQ statements in your code to do searching etc . At least have a look at the videos on this page http://msdn2.microsoft.com/en-us/vbasic/bb466226.aspx the code I described is inspired by the 5th video in the series #5 | How Do I: Create a One-To-Many Form using LINQ to SQL?

    Tuesday, January 29, 2008 11:14 AM

All replies

  • Saturday, January 26, 2008 3:37 AM
  •  

    Hi ScubaSteve20001,

     

    it didnt help at all ... I need like a sample code to start with ...

     

    Regards,

     

    Saturday, January 26, 2008 5:42 PM
  •  alnahash wrote:

    in this application I have a database in sql express 2005 consist of one table called AccessPage,, i did everything and its working fine but when I changed somthing in the datagridview it look like its changed,,, but when I close the application or even the form and open againg i didnt see the changed I did ,, why ??

     

    Simply ... I dont know how to update table using datagridview ?? I want to create a save button in a datagridview without using wizards (pure code)...

     

    Hi alnahash,

     

    Code Snippet

    Imports System.Data.SqlClient

     

    Public Class Form1

        Dim myDA As SqlDataAdapter

        Dim myDataSet As DataSet

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Dim con As SqlConnection = New SqlConnection("Data Source=.;Integrated Security=True;AttachDbFilename=|DataDirectory|\SqlDatabase.mdf")

            Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM AccessPage", con)

            con.Open()

            myDA = New SqlDataAdapter(cmd)

            'Automatically generates DeleteCommand, UpdateCommand and InsertCommand for DataAdapter object

            Dim builder As SqlCommandBuilder = New SqlCommandBuilder(myDA)

     

            myDataSet = New DataSet()

            myDA.Fill(myDataSet, "MyTable")

            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

     

            con.Close()

            con = Nothing

        End Sub

       

        ' Save data from DataGridView into Database

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Me.Validate()

            Me.myDA.Update(Me.myDataSet.Tables("MyTable"))

            Me.myDataSet.AcceptChanges()

        End Sub

     

    End Class

     

     

    In addition:

    Select/click your database file in Solution Explorer

    -> Properties Pane

    -> change the "copy to ouput directory" to "copy if newer"

     

    This blog is beneficial to you.

    https://blogs.msdn.com/smartclientdata/archive/2005/08/26/456886.aspx

     

    Tuesday, January 29, 2008 10:20 AM
  • Reference: CommandBuilder Class

    http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbcommandbuilder.aspx

    Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated database.

     

    If you use MS Access database file, here is the corresponding code sample:

    Code Snippet

    Imports System.Data.OleDb

     

    Public Class Form1

        Dim myDA As OleDbDataAdapter

        Dim myDataSet As DataSet

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     

            Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=|DataDirectory|\myDB.mdb")

            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Table1", con)

            con.Open()

            myDA = New OleDbDataAdapter(cmd)

            'Automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object

            Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA)

     

            myDataSet = New DataSet()

            myDA.Fill(myDataSet, "MyTable")

            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

     

            con.Close()

            con = Nothing

     

        End Sub

     

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Me.Validate()

            Me.myDA.Update(Me.myDataSet.Tables("MyTable"))

            Me.myDataSet.AcceptChanges()

        End Sub

    End Class

     

     

     

    Tuesday, January 29, 2008 10:23 AM
  • I think you should look into VBEE 2008 and using LINQ and the LINQ to SQL classes . I'll give you an example of a project . This project has 3 tables with relationship keys where the CustomerID key in the Customer table is linked to the CustomerID key in the Orders table which has a key linking it to the OrderDetails table . The form has 3 DataGridViews to display the data .

     

    Public Class Form1

     

    Dim DB As New BDClasses1DataContext

     

    Private Sub CustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerBindingNavigatorSaveItem.Click

    Me.Validate()

    CustomerBindingSource.EndEdit()

    Try

    DB.SubmitChanges()

    MessageBox.Show("saved")

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    End Sub

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.CustomerBindingSource.DataSource = DB.Customers

    End Sub

    End Class

     

    You see there is very little code involved and you can still use LINQ statements in your code to do searching etc . At least have a look at the videos on this page http://msdn2.microsoft.com/en-us/vbasic/bb466226.aspx the code I described is inspired by the 5th video in the series #5 | How Do I: Create a One-To-Many Form using LINQ to SQL?

    Tuesday, January 29, 2008 11:14 AM
  • Hi Martin Xie ,

     

    The code you gave me its working 100% ,, Thanx alot.. But I am trying to split the code into two buttons ..

     

    First Button for search or find

    Second Button for save ..

     

    I really tried alot but it didnt work for me ,,, could you please help with some code ..?

     

    Regards

    Sunday, February 24, 2008 6:19 PM
  •  alnahash wrote:

    First Button for search or find

    Second Button for save ..

     

    Code Snippet

    Imports System.Data.SqlClient

     

    Public Class Form1

        Dim myDA As SqlDataAdapter

        Dim myDataSet As DataSet

     

         ' First Button for search or find

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim con As SqlConnection = New SqlConnection("Data Source=.;Integrated Security=True;AttachDbFilename=|DataDirectory|\SqlDatabase.mdf")

            ' Use wildcard

      'Trackback: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2647553&SiteID=1 

            Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM AccessPage Where Filed1 Like '%" & TextBox1.Text & "%' ", con)

     ' or Where username='" & TextBox1.Text & "'

            con.Open()

            myDA = New SqlDataAdapter(cmd)

            Dim builder As SqlCommandBuilder = New SqlCommandBuilder(myDA)

     

            myDataSet = New DataSet()

            myDA.Fill(myDataSet, "MyTable")

            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView

     

            con.Close()

            con = Nothing

        End Sub

       

         ' Second Button for save

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

            Me.Validate()

            Me.myDA.Update(Me.myDataSet.Tables("MyTable"))

            Me.myDataSet.AcceptChanges()

        End Sub

     

    End Class

     

    Monday, February 25, 2008 5:31 AM
  •  Martin Xie ,

     

    This my code, and I got error when I try to save [Incorrect syntax near ','.]

     

    I Think the Problem in the updatecommand .... please help..

     

     

     

    I hope you can help,, coz couldnt solve the problem anymore ...

     

    Imports System.Data.SqlClient

    Public Class AlJassat

     

    Private Sub Search_daww_NObtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search_daww_NObtn.Click

     

    SetCommands("SELECT NName,FirstJDate FROM daww WHERE dawwNo=" & Int(Val(dawwNotxt.Text)))

    MyCmd.Connection.Open()

    SqlDA.Fill(SqlDS, "ToFind")

    MyCmd.Connection.Close()

    If SqlDS.Tables("ToFind").Rows.Count > 0 Then

    NNametxt.Text = SqlDS.Tables("ToFind").Rows(0).Item(0).ToString

    FirstJDatetxt.Text = SqlDS.Tables("ToFind").Rows(0).Item(1).ToString

    SetCommands("SELECT JDate, JQarar FROM Jal WHERE dawwno=" & Int(Val(dawwNotxt.Text)))

    MyCmd.Connection.Open()

    SqlDA.Fill(SqlDS, "ToDisp")

    MyCmd.Connection.Close()

    DataGridView1.DataSource = SqlDS.Tables("ToDisp").DefaultView

    Else

    MessageBox.Show("dawwNo '" & dawwNotxt.Text & "' not found!!!")

    End If

    End Sub

     

    Private Sub Savebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Savebtn.Click

    Validate()

    SqlDA.UpdateCommand = New SqlCommand("UPDATE jal SET JDate, JQarar", SQLConnect)

    SqlDA.Update(SqlDS, "ToDisp")

    SqlDS.AcceptChanges()

    'DataGridView1.DataSource = SqlDS.Tables("ToDisp").DefaultView

    End Sub

    Wednesday, February 27, 2008 8:38 AM
  •  alnahash wrote:

    This my code, and I got error when I try to save [Incorrect syntax near ','.]

     

    I Think the Problem in the updatecommand .... please help.

     

    SqlDA.UpdateCommand = New SqlCommand("UPDATE jal SET JDate, JQarar", SQLConnect)

    SqlDA.Update(SqlDS, "ToDisp")

     

     

    Hi alnahash,

     

    Update statement should be like this: UPDATE jal SET JDate='NewJDate', JQarar='NewJQarar' Where JDate ='OldJDate'

     

    However, when updating data back to database from DataGridView, you'd better remove this code:

    SqlDA.UpdateCommand = New SqlCommand("UPDATE jal SET JDate, JQarar", SQLConnect)

    Instead using SqlCommandBuilder to automatically generate Update Transact-SQL statements for SqlDataAdapter object.

     

     

    SqlCommandBuilder Class

    http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommandbuilder(VS.80).aspx

    Remark:

    you can create a SqlCommandBuilder object to automatically generate Transact-SQL statements for single-table updates if you set the SelectCommand property of the SqlDataAdapter. Then, any additional Transact-SQL statements that you do not set are generated by the SqlCommandBuilder.

    e.g.

    Code Snippet

            Dim adapter As New SqlDataAdapter()

            adapter.SelectCommand = New SqlCommand(queryString, connection)

            Dim builder As SqlCommandBuilder = New SqlCommandBuilder(adapter)

     

    Modified code sample:

    Code Snippet

    Imports System.Data.SqlClient

     

    Public Class AlJassat

     

        Private Sub Search_daww_NObtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search_daww_NObtn.Click

     

            SetCommands("SELECT NName,FirstJDate FROM daww WHERE dawwNo=" & Int(Val(dawwNotxt.Text)))

            MyCmd.Connection.Open()

     

            Dim SqlDA As New SqlDataAdapter()

            SqlDA.SelectCommand = New SqlCommand("SELECT * FROM daww", MyCmd.Connection)

            Dim builder As SqlCommandBuilder = New SqlCommandBuilder(SqlDA)

     

            SqlDA.Fill(SqlDS, "ToFind")

            MyCmd.Connection.Close()

     

            If SqlDS.Tables("ToFind").Rows.Count > 0 Then

                NNametxt.Text = SqlDS.Tables("ToFind").Rows(0).Item(0).ToString

                FirstJDatetxt.Text = SqlDS.Tables("ToFind").Rows(0).Item(1).ToString

                SetCommands("SELECT JDate, JQarar FROM Jal WHERE dawwno=" & Int(Val(dawwNotxt.Text)))

                MyCmd.Connection.Open()

                SqlDA.Fill(SqlDS, "ToDisp")

                MyCmd.Connection.Close()

                DataGridView1.DataSource = SqlDS.Tables("ToDisp").DefaultView

            Else

                MessageBox.Show("dawwNo '" & dawwNotxt.Text & "' not found!!!")

            End If

     

        End Sub

     

        Private Sub Savebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Savebtn.Click

            Validate()

            SqlDA.Update(SqlDS, "ToDisp")

            SqlDS.AcceptChanges()

        End Sub

    End Class

     

    By the way, please don't ignore SqlCommandBuilder object inside my code sample in my previous post.
    Wednesday, February 27, 2008 12:04 PM
  • Hi Martin,

    I got this error , Conversion failed when converting datetime from character string.

     

    and its point to

     

    SqlDA.Update(SqlDS, "ToDisp")

     

    Regards,

    Thursday, February 28, 2008 12:33 PM
  •  alnahash wrote:
    ,

    I got this error , Conversion failed when converting datetime from character string.

    and its point to

    SqlDA.Update(SqlDS, "ToDisp")

     

    You may input datetime data in incorrect datetime format on DataGridView, when you update back to database, it cannot be parsed to datetime data.

     

    Please input datetime data like this:

    2/29/2008 10:20:51 AM

    2/29/2008

    Friday, February 29, 2008 2:28 AM
  • i tried this code . it worked for Read and Delete perfectly but it is not working for Update and Insert. it gives the Error that "OledbException was unhandled" at the point of cmd.ExecuteNonQuery() Please advise where i am doing wrong in that code.
    I am using VB Express 2008 and MsAccess as database.
    Sunday, May 17, 2009 2:26 AM
  • Use commandBuilder Method..

    ---Sri's
    Thursday, September 10, 2009 3:42 PM
  • Hi Martin

    I wrote the same code.But it showed NullReference Exception.Plz help me....
    This is the error:Object reference not set to an instance of an object.
    Friday, September 25, 2009 4:19 PM
  • hai martin..........
    i'm using access database and same error with the other people


    Private

     

    Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

     

    Me.Validate()

     

    Me.myDA.Update(myDataSet, "daun")

     

    Me.myDataSet.AcceptChanges()

     

    End Sub

    -------- error was found here "INSERT INTO"


    please help me.....
    thank

    Sunday, September 27, 2009 2:02 PM
  • "--------error was found here "INSERT INTO""

    Hi mipakteh,

    It sounds like T-SQL syntax error. Please post your completed "INSERT INTO..." statement here for checking.


    "I wrote the same code.But it showed NullReference Exception.Plz help me....
    This is the error:Object reference not set to an instance of an object."


    Hi Dennis,

    It sounds that certain object has not been instantiated before being used. Please post your completed source code here for checking.

    Thank you both for your active participation in MSDN community!

    Best regards,
    Martin Xie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 28, 2009 10:01 AM
  • Imports

     

    System.Data.OleDb

    Public

     

    Class Form1

     

    Dim myDA As OleDbDataAdapter

     

    Dim myDataSet As DataSet

     

     

     

     

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

     

    Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=c:\db2.mdb")

     

    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM daun", con)

    con.Open()

    myDA =

    New OleDbDataAdapter(cmd)

     

    'Automatically generates DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object

     

    Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDA)

    myDataSet =

    New DataSet()

    myDA.Fill(myDataSet,

    "daun")

    DataGridView1.DataSource = myDataSet.Tables(

    "daun").DefaultView

    con.Close()

    con =

    Nothing

     

    End Sub

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

     

    Me.Validate()

     

    Me.myDA.Update(myDataSet, "daun")

     

    Me.myDataSet.AcceptChanges()

     

    End Sub

    End

     

    Class
    ----------------------------------------------------------------------------------------
    hai  martin xie....when i run this code.the line bellow was error

    Me.myDA.Update(myDataSet, "daun")

     



    "syntax error in INSERT INTO statemennt"

    if ur have time...help me..thank a lot








    Monday, September 28, 2009 1:10 PM
  • Hi mipakteh,

    In my opinion, the cause is that your table "
    daun" contains a column which is one reserved word (e.g. “Password” )


    Solution:

    Change the column name in your database table so that you do not use Jet 4.0 reserved word.

     

    http://support.microsoft.com/kb/248738/
    List of reserved words in Jet 4.0

     

    http://support.microsoft.com/kb/892608

    You may receive a "Syntax error in INSERT INTO statement" error message when you use ADO.NET code to access Office Access

    Similar case: http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/76f6e44c-aee2-438c-afcf-43c673c12c44/

     

     

    Best regards,
    Martin Xie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, September 29, 2009 7:25 AM
  •  

    hai martin xie.........
    bellow is my code for table "daun"


    ===================================================================
    'To make tables we use Adonet

     

    Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _

     

    " Data Source=C:\db2.mdb;User Id=admin;Password=;")

    str.AppendLine(

    "CREATE TABLE [c:\db2.mdb].[daun] (")

    str.AppendLine(

    "[NAMA LADANG] nvarchar(50) NULL,")

    str.AppendLine(

    "[TARIKH TERIMA] date NULL,")

    str.AppendLine(

    "[TARIKH SIAP] date NULL,")

    str.AppendLine(

    "[LOKASI] nvarchar(50) NULL")

    str.AppendLine(

    ")")

     

    Dim cmd As New OleDb.OleDbCommand(str.ToString, conn)

    conn.Open()

     

    Try

    cmd.ExecuteNonQuery()

     

    Catch ex As OleDb.OleDbException

    MessageBox.Show(ex.Message,

    "OleDbException")

     

    Exit Sub

     

    Catch ex As Exception

    MessageBox.Show(ex.Message,

    "GeneralException")

     

    Exit Sub

     

    End Try

    conn.Close()

    • Proposed as answer by mipakteh Saturday, October 10, 2009 2:40 PM
    Tuesday, September 29, 2009 1:54 PM
  • Hi mipakteh,

    I would like to suggest that you don't add space into column name.
    NAMA LADANG,  TARIKH TERIMA,  TARIKH SIAP.

    You can change them to:
    NAMA_LADANG,  TARIKH_TERIMA,  TARIKH_SIAP
    Or change to:
    NAMALADANG,  TARIKHTERIMA,  TARIKHSIAP.

    Please give it a try.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, September 30, 2009 3:45 AM
  • thank martin xie................it successed for add the new record.
    but..........if i to modified the data and update again .............error was occur
    Saturday, October 10, 2009 2:39 PM
  • "but..........if i to modified the data and update again .............error was occur"
    -> What's the error message please? It would be better to elaborate it.

    You can consider sending your entire project containing database file (zip package) to me for investigation. v-maxieATmicrosoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, October 12, 2009 5:53 AM
  • That's so kind of you Martin.
    Only performance counts!
    Monday, October 12, 2009 10:11 PM
  • Hi Guys

    I have the very similar problem.  I have followed the walkthrought  exectly on msdn but it doesn't work as expected.

    I have a Data Source with one database table.
    The table is from the northwind database and is called customer.
    This table is set to be in Detail mode meaning I get individuals control for
    the whole table when I drag the table into the windows form.

    In this form there is a diskett meaning that I can save data back to the
    database.

    So I do the following change some data in one of the control and then click
    the diskett symbol meaning I save the data back to the database.
    If I now go to the next record and then go back to the previous record the
    change is there.
    So I manage to change in the dataset but if I then close the application and
    look in the database my changes has not changed anything in the database.

    I can't understand why this doesn't work.  My code is as following:

    Try

     

    Me.Validate()
    Me
    .CustomersBindingSource.EndEdit()
    Me.CustomersTableAdapter.Update(Me
    .NORTHWNDDataSet.Customers)
    MsgBox("Update successful"
    )

    Catch ex As
    Exception

    MsgBox(

     

    "Update failed")

     

     

    End Try


    Thursday, January 14, 2010 2:25 PM
  • hey martin,

    thanks 4 ur solution.it works so damn well.........was working on it 4 so many days

    Friday, May 7, 2010 2:31 PM
  • Hi Martin,

    Sorry martin but your code for oledb provider is giving me an exception that "no value given for one or more required parameter"..

    when im going to do same thing it is showing me the same exception...

    can you solve it????

    Thursday, January 27, 2011 9:00 AM