I hav etried out several solutions found on the net to solve my problem but I cant seem to find the right answer.
First my Code:
I get my data into a dataGridview. but when i press button 2 again the grid does not clear it just adds the data beneath the first rows, how do I clear the grid before the next "fill" ???
Can anyone please tell me how to fix this??
First my Code:
VB.NET:
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.IO
Public Class Form2
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
Dim myCommand2 As SqlDataAdapter
Dim cbldr As SqlCommandBuilder
Dim ds As DataSet
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Test()
End Sub
Sub Test()
'Henter database tilkoplingen fra Form 1,
myConnection = Form1.cnn
myCommand = New SqlDataAdapter("SELECT * FROM Kundenavn", myConnection)
' Lag og fyll DataSet.
ds = New DataSet()
myCommand.Fill(ds, "Kundenavn")
KundenavnDataGridView.DataSource = ds.Tables("Kundenavn")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.cnn.Open()
cbldr = New SqlCommandBuilder(myCommand)
myCommand.Update(ds, "Kundenavn")
cbldr = New SqlCommandBuilder(myCommand)
myCommand.Update(ds, "Ordre")
Form1.cnn.Close()
Test()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'Henter ordre fra DB i he nhold til kundeID angitt i teksboks
myCommand = New SqlDataAdapter("SELECT * FROM Ordre WHERE KundeID =" + TextBox1.Text + "", myConnection)
myCommand.Fill(ds, "Ordre")
OrdreDataGridView.DataSource = ds.Tables("Ordre")
End Sub
End Class
I get my data into a dataGridview. but when i press button 2 again the grid does not clear it just adds the data beneath the first rows, how do I clear the grid before the next "fill" ???
Can anyone please tell me how to fix this??
Last edited: