Unable to update record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baban123
    New Member
    • Jan 2015
    • 3

    Unable to update record

    Code:
    da = New OdbcDataAdapter("select * from phone order by nm", cn)
                ds = New DataSet("phone")
                da.FillSchema(ds, SchemaType.Source, "phone")
                da.Fill(ds)
    
                Dim tblAuthors As DataTable
                tblAuthors = ds.Tables("phone")
    
                Dim drCurrent As DataRow
               
                drCurrent = tblAuthors.Rows(0)
                drCurrent.BeginEdit()
                drCurrent("ph") = "342"
                drCurrent.EndEdit()
    
                cmdBuilder = New OdbcCommandBuilder(da)
                da.Update(ds.GetChanges, "phone")
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Where is the SQL update command code?
    I only see select code.

    -Frinny

    Comment

    • baban123
      New Member
      • Jan 2015
      • 3

      #3
      I'm not doing it manually, commandbuilder is doing this for me.
      Code:
      cmdBuilder = New OdbcCommandBuilder(da)
      by this code insert, update & delete command is auto-generated...

      Error:::: there is no row at 0.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        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 OdbcCommandBuil der Class for more information on the class.

        Try modifying their code example to suit your needs:

        Code:
        Public Function SelectOdbcSrvRows(ByVal connectionString As String, ByVal tableName As String) As DataSet
        
            Dim queryString As String= "select * from phone order by nm"
        
            Dim dataSet As DataSet = New DataSet
        
            Using connection As New OdbcConnection(connectionString)
                Dim adapter As New OdbcDataAdapter()
                adapter.SelectCommand =  New OdbcCommand(queryString, connection)
                Dim builder As OdbcCommandBuilder =  New OdbcCommandBuilder(adapter)
        
                connection.Open()
        
                adapter.Fill(dataSet, tableName)
        
                ' Code to modify data in DataSet here  
        
                ' Without the OdbcCommandBuilder this line would fail.
                adapter.Update(dataSet, tableName)
            End Using 
        
            Return dataSet
        End Function
        -Frinny

        Comment

        • baban123
          New Member
          • Jan 2015
          • 3

          #5
          Guess what! It's now working properly...
          Thank you very very much!!! thanks for your help.
          I just changed this line...
          Code:
          da.Fill(ds, "phone")

          Comment

          Working...