开发者

How to commit changes to access database using datagridview in vb.net?

开发者 https://www.devze.com 2022-12-15 15:08 出处:网络
Please help, I 开发者_如何学Gogot the code below from a book but it doesnt seem to work: try oledbDataAdapter1.update(\"GH\")

Please help, I 开发者_如何学Gogot the code below from a book but it doesnt seem to work:

 try 
   oledbDataAdapter1.update("GH")
   Catch ex as exception
      msbox(ex.tostring)
   end try

I'm using ms access 2003, here is my connection string:

       Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data     Source=F:\ACCESS DATABASE\search.mdb")
    Dim cmd As OleDbCommand = New OleDbCommand("Select * from GH where IDNUMBER= '" & TextBox1.Text & "' ", cn)


First, I am not sure what you are trying to update. The update method requires a dataset or datatable. Here is a link to the MSDN website with more information about the update method - oledbdataadapter.update method.

Here is an example of what I believe you are trying to do.

dim oledbDataAdapter1 as new oledbDataAdapter("Select * from GH where IDNUMBER= '" & TextBox1.Text & "' ","Provider=Microsoft.Jet.OLEDB.4.0;Data     Source=F:\ACCESS DATABASE\search.mdb")

dim modifieddataset as dataset
oledbDataAdapter1.fill(modifieddataset)

'Make changes to dataset
...

try
     oledbDataAdapter1.update(modifieddataset)  
catch ex as exception
     msbox(ex.tostring)
end try

Finally, you should avoid allowing user input to be put directly into you SQL string. It allows SQL Injection. Here is an article that will better explain the issue - SQL Injection. HTH

0

精彩评论

暂无评论...
验证码 换一张
取 消