Well, My code is working fine I just need a way to reset the DataAdapter1 into 0 (like reset) So if the user hit the button search 2 times to shows up only 1 time the elements of database "product".. If i used the code below and hit 2 times the button the DataGridView show 10 product for examplat the first time and +10 for the second, a total of 20 products, even if I search then edit a product and search again it's fixed the previous table and prints again 2 times the table....

DataAdapter1.SelectCommand = Sql2  ''database load 
 DataAdapter1.Fill(ds2, "products")   ''dataset 


        DataGridView1.DataSource = ds2
        DataGridView1.DataMember = "products"

        SQLConnection.Close()

Thank you very much for all your help!!!
Regards!!!!

Try putting this before you re-populate, it will remove all the existing rows from your data grid, so the next time you populate it you'll only have the one set of data:

DataGridView1.Rows.Clear()

Edited 4 Years Ago by 0x90: Expanded a bit on why this code should help

well please try this code

dim con as new sqlconnection("connectionstring")
              con.open()
              dim da as new sqldataadapter("select * from table",con)
              dim dt as new datatable
              Date.fill(dt)
              datagridview1.datasource = dt

this will solve your prob :)

Regards

HI just need a way to reset the DataAdapter1 into 0 (like reset)

Set datasource to null. This way you reser it.

well please try this code

dim con as new sqlconnection("connectionstring")
              con.open()
              dim da as new sqldataadapter("select * from table",con)
              dim dt as new datatable
              Date.fill(dt)
              datagridview1.datasource = dt

this will solve your prob :)

Regards

What do you mean by Date.fill(dt)??

DataAdapter.Fill(dt)??

I have already try it..
isn't works...

Thank you !!

sorry :P

i typed wrong , this is the correct code

dim con as new sqlconnection("connectionstring")
              con.open()
              dim da as new sqldataadapter("select * from table",con)
              dim dt as new datatable
              da.fill(dt)
              datagridview1.datasource = dt

try this

sorry :P

i typed wrong , this is the correct code

dim con as new sqlconnection("connectionstring")
              con.open()
              dim da as new sqldataadapter("select * from table",con)
              dim dt as new datatable
              da.fill(dt)
              datagridview1.datasource = dt

try this

Thank you :D I will try when I come back home and I would let you know...!!

Regards!!!

Try setting dataset=nothing or dataset=null. This should work

I have already try to set the dataset into nothing or null, it's working for only 1 time.. Basically if you check my code you will understand why... Compile just read the data from database each time that the user hit the button search.. The compiler isn't understand that each time must ignore the previous details and continuous with the other.. and also can't overwrite the details, so it's adds the records again in a different rows and columns.....

Thank you for your reply anyway...!!!

Regards!!!

sorry :P

i typed wrong , this is the correct code

dim con as new sqlconnection("connectionstring")
              con.open()
              dim da as new sqldataadapter("select * from table",con)
              dim dt as new datatable
              da.fill(dt)
              datagridview1.datasource = dt

try this

Well I have try it and the truth is that isn't works, I don't know why.. Seams something is going wrong.... Also I have the same problem as previous (The records appears 2 times if the user search double times.) But another strange problem is uppear.. If i used your code I can't edit the records..!! :-/ This is very weird since alsmost my code is similar to your.. if you have any other hint point that will help me I will be glad to vote you up!!! :D

Regards
!!!

please show your code , so that i can check it ,

Here is my code::
Thanks anywat!!!! :)

Dim Sql2 As MySqlCommand = New MySqlCommand("SELECT * FROM products", SQLConnection)   

            DataAdapter1.SelectCommand = Sql2  ''database load 

            DataAdapter1.Fill(ds2)   ''dataset 
            DataGridView1.DataSource = ds2

please first you should know the difference between dataset and datatable , when ever you are using dataset then please define a table in it , like this

dim ds2 as new dataset
ds2.table("table").clear()
'now after this fill dataset like this 
DataAdapter1.fill(ds2,"table")
'now assign the data source to the grid
DataGridView1.datasource = ds2.table("table")

this will work fine , in single dataset there can be one or more then one tables . so when ever you are using single table then there is no need to use dataset , use datatable .

Best Regards

Comments
Perfect!!!!

please first you should know the difference between dataset and datatable , when ever you are using dataset then please define a table in it , like this

dim ds2 as new dataset
ds2.table("table").clear()
'now after this fill dataset like this 
DataAdapter1.fill(ds2,"table")
'now assign the data source to the grid
DataGridView1.datasource = ds2.table("table")

this will work fine , in single dataset there can be one or more then one tables . so when ever you are using single table then there is no need to use dataset , use datatable .

Best Regards

Thank you very MUCH, you really help me.! It's works with the following code::!! :D

DataGridView1.Columns.Clear()                 ''CLEARING THE DATAGRIDVIEW1
        DataGridView1.DataBindings.Clear()
        ds2.Clear()            ''CLEAR the data 
        DataGridView1.DataSource = Nothing
        DataGridView1.DataMember = Nothing
This question has already been answered. Start a new discussion instead.