468,133 Members | 1,184 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

Unable to update record

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
4 1096
Frinavale
9,735 Expert Mod 8TB
Where is the SQL update command code?
I only see select code.

-Frinny
Jan 8 '15 #2
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
9,735 Expert Mod 8TB
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
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.

Similar topics

1 post views Thread by oldandgrey | last post: by
1 post views Thread by toedipper | last post: by
2 posts views Thread by Tinius | last post: by
1 post views Thread by Daniel | last post: by
1 post views Thread by dreamy | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.