tableadapter.fill(datatable) fills the row that was not added to the datatable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lyasta
    New Member
    • Aug 2010
    • 4

    tableadapter.fill(datatable) fills the row that was not added to the datatable

    Hi,
    I am trying to add NewRow to the database by using datatable in dataset, but before I do that I want to make sure that row is not already there. I create new row for the datatable I am working with, fill it with information. I fill datatable with the row from database that has the same primary key as my NewRow by using tableadapter.fi ll method, but when I do that my NewRow that was never added to the datatable is filled with information from database(and not information that I assigned to it). I count rows in my datatable before I fill it and it's 0, so why is my NewRow affected by Fill command? (I am using VB.NET 2005 Framework 2.0)
    This is my first post so I hope I was clear enough.
    Thank you in advance.

    Code:
    Dim newRow As dsMain.TF_INFORow
    newRow = Me.DsMain1.TF_INFO.NewTF_INFORow
    newRow.Owner_Name="bla"
    Me.TaTF_INFO1.FillByVehicle(Me.DsMain1.TF_INFO)
    'newRow is lost - "bla" is not there
  • murtazadoc
    New Member
    • Aug 2010
    • 5

    #2
    Although I didn't got your exact query, I think this is what you are looking for...
    You can try adding a row in ds manner to a dataset

    Code:
    conn.Open()
    cmd.CommandText = "SELECT * FROM tablename where 1=2"
    cmd.ExecuteNonQuery()
    da.SelectCommand = cmd
    da.Fill(ds)
    Dim addRow As DataRow = ds.Tables(0).NewRow
    
    addRow("rowname") = txtName.Text
                    
    ds.Tables(0).Rows.Add(addRow)
    conn.Close()
    Still if you comprehend mr on the blank part, it would be much easier for the help...
    Last edited by Frinavale; Aug 10 '10, 02:45 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags. Please do not use SMS speak: Use proper English when replying.

    Comment

    • lyasta
      New Member
      • Aug 2010
      • 4

      #3
      Thank you for reply, but I didn't exactly have a problem with adding new row to the table in dataset. I figured out what I was doing wrong. It was "WITH" operator:
      Code:
      With newRow
      If (.Owner_Name = Me.DsMain1.TF_INFO(0).Owner_Name)Then
      'this would always give me True because 
      'Me.DsMain1.TF_INFO(0).Owner_Name was recognized as
      'newRow's Owner_Name and not value from the actual table row
      End If
      End With

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Lyasta, you didn't actually state that you were having problems with the "WITH" section of the code...you didn't even post the "WITH" section.

        Please post the entire function because I can't see what newRow is referring to.

        -Frinny

        Comment

        • lyasta
          New Member
          • Aug 2010
          • 4

          #5
          Frinavale,
          Originally I didn't think that "WITH" was my problem. After I stopped using it (because I thought that it was giving me a hard time) I made a bunch of other changes to the program and at this point can’t repopulate my error. Still confused on what exactly happened...
          Sorry for wasting your time...

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Haha that's ok :)
            I hate it when things fix themselves!

            I'm glad you sorted it out though.

            Feel free to post again if you have any other questions/problems.

            -Frinny

            Comment

            Working...