I have load a csv file using the code below
Dim fi
Dim conn
Dim adapter1 As New OleDbDataAdapter
Dim ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
fi = New FileInfo("C:\path\Book1.csv")
conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName)
conn.Open()
adapter1.SelectCommand = New OleDbCommand("SELECT * FROM " & fi.Name, conn)
adapter1.Fill(ds, "DATA")
DataGridView1.DataSource = ds.Tables(0).DefaultView
End Sub
Now, I want to execute a SQL query like create, select, update, etc inside the gridview. For example, I want to create a new column "test" and fill that column with the values from column "a" and "b". But I get error. Can you please correct the code?
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
DataGridView2.Columns.Add("test", "test")
adapter1.SelectCommand = New OleDbCommand("Update Datagridview1 SET test = a + b", conn)
Dim dsA As New DataSet
adapter1.Fill(dsA, "DATA")
DataGridView2.DataSource = dsA.Tables(0).DefaultView
Catch exp As Exception
MsgBox("Error : " & exp.Message)
End Try
End Sub