M
meoabc
Guest
Hello,
Im trying to write a code, that update to data source from dataset throught DataAdapter.
Search in MSDN I got an example and Ive written the same code as they did:
But nothing changes when I submit the button, the data source is the same. What wrong is it ? I dont know. Can you show me something ?
Thanks in advance
Im trying to write a code, that update to data source from dataset throught DataAdapter.
Search in MSDN I got an example and Ive written the same code as they did:
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim ConnString As String = "Provider=Microsoft.Jet.OleDB.4.0; Data
source=C:\GiaHH.mdb"
Dim SelString As String = "Select * from category"
Dim UpConnection As New OleDb.OleDbConnection(ConnString)
Dim UpDataAdapter As New OleDb.OleDbDataAdapter(SelString,
ConnString)
UpDataAdapter.UpdateCommand = New OleDb.OleDbCommand("Update
category set CategoryName=? where category_ID=?", UpConnection)
UpDataAdapter.UpdateCommand.Parameters.Add("@categoryName",
OleDbType.VarChar, 100, "CategoryName")
Dim Originvalue As OleDb.OleDbParameter =
UpDataAdapter.UpdateCommand.Parameters.Add("@category_ID",
OleDbType.Integer)
Originvalue.SourceColumn = "Category_ID"
Originvalue.SourceVersion = DataRowVersion.Original
Dim UpDataSet As New DataSet()
DataGrid1.DataSource = UpDataSet
UpDataAdapter.Fill(UpDataSet, "category")
Dim UpRow As DataRow = UpDataSet.Tables("category").Rows(0)
UpRow("CategoryName") = "New Category"
UpDataAdapter.Update(UpDataSet, "category")
End Sub
Thanks in advance
Last edited by a moderator: