ado.net problem

  • 15 years ago

    Hi All,


    Im having some problems with copying data from my dataset back to my access database. All im trying to do is get the contents of TextBox1 into the finalSolution field. I can't understand it im getting no errors and no updated data, even though im using the update method?


    Also how is Console.WriteLine meant to work should a dos screen pop up or ?


    Heres the code


    Private Sub Progress_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated


    Dim db As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\helpdesk.mdb;")
    Dim faultsDA As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM faults", db)


    faultsDA.UpdateCommand = New OleDbCommand("SELECT * FROM faults ")
    Dim faultsDS As DataSet = New DataSet()


    db.Open()
    faultsDA.Fill(faultsDS, "faults")


    Dim faultsRow As System.Data.DataRow
    For Each faultsRow In faultsDS.Tables("faults").Rows
    Console.WriteLine("Company Name: " & faultsRow("userName"))
    faultsRow("finalSolution") = TextBox1.Text
    faultsRow.AcceptChanges()
    Next faultsRow


    faultsDA.Update(faultsDS, "faults")
    MsgBox("finito !")


    Thanks In Advance!!

  • 15 years ago

    Your DataAdapter is configured incorrectly. The UpdateCommand should be a Sql statement or stored procedure that updates the database but you have a select command. There are command properties of the DataAdapter:-


    SelectCommand
    UpdateCommand
    InsertCommand
    DeleteCommand


    You should set the update command to a sql statement that updates the database "update table set fieldname=" etc.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If Java had true garbage collection, most programs would delete themselves upon execution.” - Robert Sewell