By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Unable to update record

P: 3
Expand|Select|Wrap|Line Numbers
  1. da = New OdbcDataAdapter("select * from phone order by nm", cn)
  2.             ds = New DataSet("phone")
  3.             da.FillSchema(ds, SchemaType.Source, "phone")
  4.             da.Fill(ds)
  5.  
  6.             Dim tblAuthors As DataTable
  7.             tblAuthors = ds.Tables("phone")
  8.  
  9.             Dim drCurrent As DataRow
  10.  
  11.             drCurrent = tblAuthors.Rows(0)
  12.             drCurrent.BeginEdit()
  13.             drCurrent("ph") = "342"
  14.             drCurrent.EndEdit()
  15.  
  16.             cmdBuilder = New OdbcCommandBuilder(da)
  17.             da.Update(ds.GetChanges, "phone")
  18.  
Jan 8 '15 #1
Share this Question
Share on Google+
4 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Where is the SQL update command code?
I only see select code.

-Frinny
Jan 8 '15 #2

P: 3
I'm not doing it manually, commandbuilder is doing this for me.
Expand|Select|Wrap|Line Numbers
  1. cmdBuilder = New OdbcCommandBuilder(da)
  2.  
by this code insert, update & delete command is auto-generated...

Error:::: there is no row at 0.
Jan 8 '15 #3

Frinavale
Expert Mod 5K+
P: 9,731
Sorry I didn't see the command builder.

I actually have never used a tool that generates sql commands for me...I guess I'm a bit of a control freak and like to ensure that the statements are correct by supplying them to my data adapters manually.

Anyway, I took a look at the OdbcCommandBuilder Class for more information on the class.

Try modifying their code example to suit your needs:

Expand|Select|Wrap|Line Numbers
  1. Public Function SelectOdbcSrvRows(ByVal connectionString As String, ByVal tableName As String) As DataSet
  2.  
  3.     Dim queryString As String= "select * from phone order by nm"
  4.  
  5.     Dim dataSet As DataSet = New DataSet
  6.  
  7.     Using connection As New OdbcConnection(connectionString)
  8.         Dim adapter As New OdbcDataAdapter()
  9.         adapter.SelectCommand =  New OdbcCommand(queryString, connection)
  10.         Dim builder As OdbcCommandBuilder =  New OdbcCommandBuilder(adapter)
  11.  
  12.         connection.Open()
  13.  
  14.         adapter.Fill(dataSet, tableName)
  15.  
  16.         ' Code to modify data in DataSet here  
  17.  
  18.         ' Without the OdbcCommandBuilder this line would fail.
  19.         adapter.Update(dataSet, tableName)
  20.     End Using 
  21.  
  22.     Return dataSet
  23. End Function
-Frinny
Jan 8 '15 #4

P: 3
Guess what! It's now working properly...
Thank you very very much!!! thanks for your help.
I just changed this line...
Expand|Select|Wrap|Line Numbers
  1. da.Fill(ds, "phone")
  2.  
Jan 9 '15 #5

Post your reply

Sign in to post your reply or Sign up for a free account.