Click here to Skip to main content
14,430,746 members
Rate this:
Please Sign up or sign in to vote.
See more:
i'm working with a new module for my system. but whenever i use dispose() i still get the old value and it will add to the new value. I already use .dispose() to the query i used but it has no effect whenever i search for a new data it will just add the old value to the new generated value. I don't have any problem displaying the data. The problem i have is i have to close the form to search a new data instead of just searching.

What I have tried:

Private Sub dataload()
   DataGridView1.DataSource = Nothing
   Dim ds As DataSet
   Dim dr as DataRow
   ds = sqlFunctions.getTable(tmp_str1, connectionstring)

   For i = 0 To ds.Tables(0).Rows.Count - 1       
     dr = ds.Tables(0).Rows(i)
End Sub
Updated 30-Sep-19 23:15pm
Richard Deeming 1-Oct-19 11:44am
ds = sqlFunctions.getTable(tmp_str1, connectionstring)

It looks like you've written a helper method which will force you to write code which is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
xkarmax 2-Oct-19 1:21am
Thanks! will surely read that article and review my codes.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Why are you manually adding rows to the DataGridView instead of using a DataSource? Every time you add a new set of data from the database you will still have the old data. Use a DataSource parameter to make things work correctly.
xkarmax 1-Oct-19 22:47pm
so i should use this
ds = sqlFunctions.getTable(tmp_str1, connectionstring)
DataGridView1.DataSource = ds.Table(0) ??
Richard MacCutchan 2-Oct-19 3:39am
I would expect that to be correct. A simple test run will prove it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100