dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: sqldataadapter.Update error

  1. #1
    Join Date
    Jan 2007
    Posts
    1

    sqldataadapter.Update error

    Hi,

    I'm getting an error when trying to update using dataAdapter.

    The error I'm getting is:

    System.Data.DBConcurrencyException: Concurrency violation: the UpdateCommand affected 0 records.
    at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
    at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)

    I start by creating a dataadapter using 2 select statements as below:

    daUpdateFileData = new SqlDataAdapter("select id, folder, fileName, fileSize, fileDate, isLocked, dtsCreated from dbo.ftp_files where (IsLocked = 1); select id, folder, fileName, fileSize, fileDate, isLocked, dtsCreated from dbo.ftp_files_results", sqlConn);

    create the insert update and delete commands using:


    SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daUpdateFileData);

    fill the dataset using

    daUpdateFileData.Fill(dsUpdateFileData, "test_table");

    set a datatable to the second table using:

    DataTable updatetbl = dsUpdateFileData.Tables[1];

    then loop through this table and update the dataset using

    daUpdateFileData.Update(dsUpdateFileData, "test_table1");

    any ideas whats wrong as I thought if you pass a tablename to the fill method it creates incremental names for the tables with multiple datasest i.e tablenameN...

  2. #2
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Resolved Re: sqldataadapter.Update error

    I did not want to continue reading your post , because what you wrote even in your comment is wrong. In your Command object your Query does not even update , here is an example of Update


    Code:
      Dim  con as  New SqlConnection(constr)
    
      Dim  cmdUpdate  as  New SqlCommand()
    
      Dim da As new  SqlDataAdapter()
    
      cmdUpdate.CommandType = CommandType.Text
    
      cmdUpdate.CommandTimeout = 0
    
      cmdUpdate.Connection = con
    
      cmdUpdate.CommandText = "Update Mytable set name= 'Vuyiswa'        where  ID_No = 81 " 
        
            Try
                con.Open()
    
                   da.Update(ds,"Mytable")
    
                con.Close()
    
            Catch ex As SqlClient.SqlException
    
                MsgBox(ex.Message)
    
            End Try
    Start Fixing your code if you have Structured it like this and start asking Question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)