Clearing a dataset

  • Thread starter Thread starter Nita
  • Start date Start date
N

Nita

Hi,
Im a sort of newbie when it comes to VB.NET, so forgive me if this is
a simple question. I have a dataset i wish to clear, ive used a
parameterised stored procedure from MS Access. Currently im using:
DtsCustomerIdParam1.Clear()

to clear it, and it does, according to a data grid i put in to test
it, but when i go and try and run the stored procedure again, it
comes up with the same result as the first time.
Im selecting two things from cbo boxes, and wanting the result to be
put into another cbo box, it works the first time, but each time
there after it gives the same result as the first time.

I was wondering if there is a difference in the clear statment, as it
works for stored procedures that dont have parameters.

Any help is greatly appreciated.

Nita
 
Hi Nita,

Why should it not?

The datagrid holds its reference to the datasource when you clears the
dataset.

So when you run the same stored procedure to fill the dataset again, the
datagrid shows exactly as it was.

What do I mis?

Cor
 
Hi,

Like Cor says you are clearing the dataset correctly. From reading
your question I was wondering if you forgot to change a parameter for
the stored procedure before running it again.

Ken
-------------
 
as its a query with parameters, the result that the query returns is
going to vary with each diffrent set of parameters i give it. Now it
works for the first set of parameters i give it, but every set there
after return the same as what the first set did.

as an example, what im doing is giving it a name and a postcode, so it
will return an id for that person.
say the first time i select the parameters, i give it name x and
postcode 1234, it will return the id as 1
now the next time i want to run it, straight after i just entered the
previous name and postcode. i put in y for the name and 4321 for the
postcode, i still get the id comming back as 1, although i kow and
can check that the id that should be returned is 2.

Hope i explained it better this time. Thanks for the help so far
though.

Nita
 
Hi,

Maybe this will help. It uses the northwind database.

Dim da As SqlDataAdapter
Dim ds As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim conn As SqlConnection
Dim strConn As String
Dim drCustomer As SqlDataReader
Dim cmd As SqlCommand
Dim cmdOrders As SqlCommand

strConn = "Server = " + Environment.MachineName + ";"
strConn += "Database = NorthWind;"
strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)
cmd = New SqlCommand("Select * from Customers", conn)
cmdOrders = New SqlCommand("CustOrderHist", conn)
cmdOrders.CommandType = CommandType.StoredProcedure
cmdOrders.Parameters.Add("@CustomerID",
System.Data.SqlDbType.NText)
da = New SqlDataAdapter(cmdOrders)
conn.Open()

drCustomer = cmd.ExecuteReader
Do While drCustomer.Read
ComboBox1.Items.Add(drCustomer.Item("CustomerID").ToString)
Loop
conn.Close()
ComboBox1.SelectedIndex = 0
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged

da.SelectCommand.Parameters("@CustomerID").Value =
ComboBox1.SelectedItem.ToString
ds.Clear()

da.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
End Sub

Ken
--------------------------
 
Set your combobox.datasource = Nothing before you re-populate.

Nita said:
Hi,
Im a sort of newbie when it comes to VB.NET, so forgive me if this is
a simple question. I have a dataset i wish to clear, ive used a
parameterised stored procedure from MS Access. Currently im using:
DtsCustomerIdParam1.Clear()

to clear it, and it does, according to a data grid i put in to test
it, but when i go and try and run the stored procedure again, it
comes up with the same result as the first time.
Im selecting two things from cbo boxes, and wanting the result to be
put into another cbo box, it works the first time, but each time
there after it gives the same result as the first time.

I was wondering if there is a difference in the clear statment, as it
works for stored procedures that dont have parameters.

Any help is greatly appreciated.

Nita
 
Back
Top