I have a program to display queries to a SQL db. I type my query in a
textbox and click a button and the results display in a datagrid. I
could use either dataset or datatable to read the data in then I make
the datagrid.dataso urce = myds.Tables(0) or mydt. Now what I want is to
be able to change the query and click the button again and get the new
results. I can use clear() to clear the data from a ds/dt but I need
the structure gone too. How can I do this? Here is sample code using dt.
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim Sql2000DataAdap ter As New
System.Data.Sql Client.SqlDataA dapter(TextBox2 .Text, TextBox1.Text)
mydt.Clear()
Try
Sql2000DataAdap ter.Fill(mydt)
Catch ex As Exception
MessageBox.Show ("Error: " & ex.Message)
Exit Sub
End Try
DataGridView1.D ataSource = mydt
End Sub
Private Sub DataGridView1_C ellContentClick (ByVal sender As
System.Object, ByVal e As
System.Windows. Forms.DataGridV iewCellEventArg s) Handles
DataGridView1.C ellContentClick
TextBox3.Text = DataGridView1.C urrentCell.Valu e
End Sub
textbox and click a button and the results display in a datagrid. I
could use either dataset or datatable to read the data in then I make
the datagrid.dataso urce = myds.Tables(0) or mydt. Now what I want is to
be able to change the query and click the button again and get the new
results. I can use clear() to clear the data from a ds/dt but I need
the structure gone too. How can I do this? Here is sample code using dt.
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim Sql2000DataAdap ter As New
System.Data.Sql Client.SqlDataA dapter(TextBox2 .Text, TextBox1.Text)
mydt.Clear()
Try
Sql2000DataAdap ter.Fill(mydt)
Catch ex As Exception
MessageBox.Show ("Error: " & ex.Message)
Exit Sub
End Try
DataGridView1.D ataSource = mydt
End Sub
Private Sub DataGridView1_C ellContentClick (ByVal sender As
System.Object, ByVal e As
System.Windows. Forms.DataGridV iewCellEventArg s) Handles
DataGridView1.C ellContentClick
TextBox3.Text = DataGridView1.C urrentCell.Valu e
End Sub
Comment