-
February 15th, 2010, 05:36 AM
#1
dataset question
hi,
my script is working fine, i have a button that executes a query and fill my dataset.
but when i click again the button and execute the query it is just adding it to my dataset.
i need to reset the dataset when i click the button, because it is a new query.
Code:
Private Sub bttnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnStart.Click
Dim conn As New OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ApplicationKit.accdb"
Dim MyVariable As String
Dim ChosenBttn As String
Dim Vowel As String
Dim Table As String
Table = "Word"
Vowel = "Word"
MyVariable = cbPhonemes.SelectedIndex
MyVariable = MyVariable + 1
If bttnInitial.Checked = True Then
ChosenBttn = "Initial"
End If
If bttnMedial.Checked = True Then
ChosenBttn = "Medial"
End If
If bttnFinal.Checked = True Then
ChosenBttn = "Final"
End If
Dim strSQL As String = "SELECT word, meaning FROM word WHERE (ID = " & MyVariable & ") AND ( [Position] = '" & ChosenBttn & "')"
Dim da As New OleDbDataAdapter(strSQL, conn)
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then 'Check to see if the table is empty
lblWord.Text = ds.Tables(0).Rows(0).Item("Word").ToString()
End If
End Sub
-
February 15th, 2010, 06:02 AM
#2
Re: dataset question
as ds is not local to the procedure, it never "die" and fill method called that way adds to it, do not substitute or refresh.
If you need it alive, you have a couple of options:
1)before filling it again, call
ds.Tables.Clear()
2)or use an overload of the fill method of OledbDataAdapter:
Table="word"
...
da.Fill(Ds, Table)
see:
http://msdn.microsoft.com/en-us/library/y4b211hz.aspx
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
February 15th, 2010, 10:09 PM
#3
Re: dataset question
thank you very much, it works like a charm...
-
February 19th, 2010, 02:08 AM
#4
Re: dataset question
Originally Posted by homer.favenir
thank you very much, it works like a charm...
Yeah, Cimperiali rocks!
Last edited by ddclondon; February 19th, 2010 at 05:28 AM.
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
|