Super_Grover
Active member
- Joined
 - Apr 7, 2010
 
- Messages
 - 32
 
- Programming Experience
 - Beginner
 
Hi all,
I'm struggling with two problems involving datagridview and an access databse. I'm working with VS2008 (VB2008) which seems to differ quite a bit from 2005 on this subject. All I could find on the internet involved mainly VB2005 and didn't work for me.
Problem 1:
Saving new row to db. I have the following code. Row is added in the DGV (and dataset I guess), but is not written for real to the db. Even if I close the appl and reopen the row is still there, but after a couple of minutes it appears not to be. Opening the db directly in Access show that the new data is not saved. Any ideas guys?
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Problem two:
I would like to use different queries on this DGV from the same db. So, say a couple of buttons which represent another selection of the db. I tried defining another dataAdapter which holds another query, but can't figure out how to display other data in the DGV than the bound data in the first dataset.
Any help is appreciated!
	
		
			
		
		
	
				
			I'm struggling with two problems involving datagridview and an access databse. I'm working with VS2008 (VB2008) which seems to differ quite a bit from 2005 on this subject. All I could find on the internet involved mainly VB2005 and didn't work for me.
Problem 1:
Saving new row to db. I have the following code. Row is added in the DGV (and dataset I guess), but is not written for real to the db. Even if I close the appl and reopen the row is still there, but after a couple of minutes it appears not to be. Opening the db directly in Access show that the new data is not saved. Any ideas guys?
			
				VB.NET:
			
		
		
		Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Add.Click
        Dim newToetsingRow As DataRow = SampleRegDataSet.Tables("tbl_toetsingen").NewRow()
        Dim li_aantal As Integer = Convert.ToInt32(mtxt_aantal.Text)
        Dim li_akkoord As Integer = Convert.ToInt32(mtxt_akkoord.Text)
        Dim li_betaald As Integer = Convert.ToInt32(mtxt_betaald.Text)
        Dim ls_opm As String = mtxt_opm.Text
        Dim ld_datum As Date = dtp_datum.Value.Date
        Dim li_totaalbedrag As Integer = Convert.ToInt32(mtxt_aantal.Text) * 25
        newToetsingRow("User_ID") = gi_iser
        newToetsingRow("Datum") = ld_datum
        newToetsingRow("Aantal_toetsingen") = li_aantal
        newToetsingRow("Aantal_akkoord") = li_akkoord
        newToetsingRow("Aantal_betaald") = li_betaald
        newToetsingRow("Totaal_bedrag") = li_totaalbedrag
        newToetsingRow("Opmerkingen") = ls_opm
        SampleRegDataSet.Tables("tbl_toetsingen").Rows.Add(newToetsingRow)
        Me.Tbl_toetsingenTableAdapter.Update(Me.SampleRegDataSet)
        MsgBox("New row added!")
End Sub
	Problem two:
I would like to use different queries on this DGV from the same db. So, say a couple of buttons which represent another selection of the db. I tried defining another dataAdapter which holds another query, but can't figure out how to display other data in the DGV than the bound data in the first dataset.
Any help is appreciated!