Question problem with updating to database

Sayed12

Member
Joined
Jun 7, 2011
Messages
8
Programming Experience
Beginner
hi I am creating a very simple project in vb 2008 with 2 forms(form1,form2)
form1 is in detail view and form2 is in datagrid view, both are bound to the same database LAF.mdb and the table name is Table1. all it does is save new record to the database from form1 and also when the record is selected from form2 in datagrid view it pops up with the specific record, which i need to then update back to the database.I have used wizard to make the connection to database for both forms. Now I can save new record(in form1), populate the datagrid view with all the recods or by filtering and also can open selected record with all details correctly into form1 from form2.then when i try to update the record it only updates into the datagridview but doesnt update in the database.and also if i click onto show all records or refresh datagridview it resets the old record into the datagridview.

On form1 i have 4 buttons and also binding navigator and lots of textboxes, checkboxes,combo and datetimepickers.
add new(button 4)
save(button2)
update(does the same thing as save button3)
search(opens form1 button1)

form2 i have 4 buttons and a datagrid view which was dragged from datasource window
button2 show all
button 4 clear dgv
button3 to show the record on new form
button1 for filtering
VB.NET:
FORM1


Public Class Form1

  Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub



    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Validate()
        Me.Table1BindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.LAFDataSet)
    End Sub

   

    Public Property DataSource() As Object
        Get
            Return Me.Table1BindingSource.DataSource
        End Get
        Set(ByVal value As Object)
            Me.Table1BindingSource.DataSource = value
        End Set
    End Property


    
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Validate()
        Me.Table1BindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.LAFDataSet)
    End Sub

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

    End Sub

    Private Sub Table1BindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.Table1BindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.LAFDataSet)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'LAFDataSet.Table1' table. You can move, or remove it, as needed.

    End Sub
End Class



FORM2

Public Class Form2


    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'LAFDataSet.Table1' table. You can move, or remove it, as needed.
        Me.Table1BindingSource.DataSource = LAFDataSet.Table1
        Me.Table1DataGridView.DataSource = Me.Table1BindingSource
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("Reference no required !!!!")
        Else
            Me.Table1BindingSource.Filter = "[ID]='" & TextBox1.Text & "'"
            Me.Table1TableAdapter.Fill(Me.LAFDataSet.Table1)
            Table1DataGridView.DataSource = Table1BindingSource
            Table1DataGridView.Refresh()
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Table1DataGridView.DataSource = LAFDataSet.Table1
        Table1DataGridView.Refresh()
        Me.Table1TableAdapter.Fill(Me.LAFDataSet.Table1)

    End Sub



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

        Table1DataGridView.DataSource = Nothing
        Table1DataGridView.Refresh()
        Me.Refresh()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    End Sub


    Private Sub Table1DataGridView_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table1DataGridView.CellDoubleClick
        Dim f1 As New Form1
        f1.Table1BindingSource.DataSource = Me.Table1BindingSource(e.RowIndex)
        f1.ShowDialog()
    End Sub

   
End Class

if you need any more details pls ask me. I desperately need it to be running asap.Any help will be greatly appreciated. thanks in advance.
 
read the DNU link inn my signature and make sure it's not that..

elsewise, if your form2 is setting the datasource of its grid to the datasource property you've exposed on form1 then I'm not sure how what you are describing is happening.. Two data bound controls bound through the same bindingsource to the same data model will show the same data, guaranteed. you may have to post the code of your project. Perform a Clean Solution on the build menu first though, so we dont have your zip file bloated by binaries
 
Cjard thank you very much for your reply. I am desperately looking for the answer.i am sending you the project file.all i am trying to do is to give option to user to add,save,delete and update record in form 1. On my project you will notice if you double click the cell in form2 then on form1 you cant add new record and it doesnt update in the database only in the gridview, only for once and if you clear the gridview the result is gone.I also need to give more options in searching. need to search by date.User should be able to give one or many search criteria and it should show the result from database. however in form1 i am using list item in combo boxes .they are not bound. i need to know code for searching by date pls and also how to search by multiple criteria. for example, if user puts in 2 or more criteria the record has to match all of thoes crieteria. I need to put in 8 different criterias .pls advise me how i can do that. example would be really helpful for me.i tried to invisible some controls on the new form (the form that pops up after clicking the row in datagrid, it doesnt workat all).mate need your help..pls:confused:
 

Attachments

  • WindowsApplication9.zip
    90.6 KB · Views: 31
Last edited by a moderator:

Latest posts

Back
Top