|
-
Feb 26th, 2009, 10:27 AM
#1
Thread Starter
New Member
Problem with adding and refreshing
This may be a stupid question, but I'm fairly new at this.
Anyway I have this form where I display data from my database. I use a generic list for this.
I also have an area on the same form where I can add items to my database. So when I click my Save button I also want to clear the generic and 'recall' the data, so the things I added will also be displayed.
However this won't work when put all the code for this in the Save button. I can add things to the database, but refreshing the data doesn't work.
When I use a second button, with which I clear the generic list and recall the data, after I added something, it does work.
Is there a way to do all this with the same button?
-
Feb 26th, 2009, 10:39 AM
#2
Hyperactive Member
Re: Problem with adding and refreshing
EDIT: Welcome to the vbforums! This is a great place to seek help and learn by some great examples, unlike mine below. 
Are you using a dataset to load the data?
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveData()
RefreshData()
End Sub
Private Sub SaveData
If Not Me.GetConnection Then Exit Sub
Me.DataAdapter.Update(Me.DataSet)
Me.SqlConnection1.Close()
End Sub
Private Sub RefreshData()
Me.Dataset.Clear()
'open connection
If Not Me.GetConnection Then Exit Sub
Me.DataAdapter.Fill(Me.Dataset)
Me.SqlConnection1.Close()
End Sub
Regardless of how you're doing it, you need to do your save procedure and clear out where ever you're storing your data, Then Call a procedure to Clear the data and reselect it.
Tuber
"I don't know the rules"
-
Feb 26th, 2009, 12:05 PM
#3
Thread Starter
New Member
Re: Problem with adding and refreshing
No I don't use a dataset.
Let me show you my form to make things more clear. Some of it is in dutch, but the marked data is what I get from my database.

This is how is load data
Code:
Public Sub dataOproepen()
Dim sqlCmd As String
sqlCmd = "SELECT * FROM tbl_program WHERE Maand = '" & Now.Month & "' ORDER BY Dag ASC"
Dim adapter As New OleDb.OleDbDataAdapter(sqlCmd, "Provider=Microsoft.Jet.OlEDB.4.0; Data source=" & My.Settings.database)
Dim table As New DataTable
adapter.Fill(table)
Dim teller As Integer
For teller = 0 To table.Rows.Count - 1
Dim dr As DataRow = table.Rows(teller)
Dim J As New Program_Class
J.aantalKM = dr.Item(1)
J.aantalM = dr.Item(2)
J.dag = dr.Item(3)
J.maand = dr.Item(4)
J.jaar = dr.Item(5)
J.weekdag = dr.Item(6)
If J.jaar = Now.Year Then
If J.dag >= Now.Day Then
ProgramLijst.Add(J)
End If
End If
Next
'What I use to fill in the labels
invullen()
End Sub
What this form basicly does, is show the first upcoming date, and then the next one.
As you can see the next date the 28th. What I want to do is when I add a new item with as date the 27th of februari, that it would show this as the next program.
This is the code for the save button.
Code:
Private Sub btnOpslaan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpslaan.Click
datum = DateTimePicker1.Value
Dim dag As String
dag = DateAndTime.Day(datum)
Dim p As New Program_Class
p.SaveProgram(dag, Month(datum), Year(datum), datum.ToString("dddd"), numericKM.Value, numericMeter.Value)
'my generic list
ProgramLijst.Clear()
dataoproepen()
End Sub
The clearing of the generic list and reloading the data is what doesn't work. However if I put that code in a different button it does work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|