By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,729 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,729 IT Pros & Developers. It's quick & easy.

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

P: 4
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.fill 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.

Expand|Select|Wrap|Line Numbers
  1. Dim newRow As dsMain.TF_INFORow
  2. newRow = Me.DsMain1.TF_INFO.NewTF_INFORow
  3. newRow.Owner_Name="bla"
  4. Me.TaTF_INFO1.FillByVehicle(Me.DsMain1.TF_INFO)
  5. 'newRow is lost - "bla" is not there
Aug 6 '10 #1
Share this Question
Share on Google+
5 Replies

P: 5
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

Expand|Select|Wrap|Line Numbers
  1. conn.Open()
  2. cmd.CommandText = "SELECT * FROM tablename where 1=2"
  3. cmd.ExecuteNonQuery()
  4. da.SelectCommand = cmd
  5. da.Fill(ds)
  6. Dim addRow As DataRow = ds.Tables(0).NewRow
  8. addRow("rowname") = txtName.Text
  10. ds.Tables(0).Rows.Add(addRow)
  11. conn.Close()
Still if you comprehend mr on the blank part, it would be much easier for the help...
Aug 6 '10 #2

P: 4
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:
Expand|Select|Wrap|Line Numbers
  1. With newRow
  2. If (.Owner_Name = Me.DsMain1.TF_INFO(0).Owner_Name)Then
  3. 'this would always give me True because 
  4. 'Me.DsMain1.TF_INFO(0).Owner_Name was recognized as
  5. 'newRow's Owner_Name and not value from the actual table row
  6. End If
  7. End With
Aug 10 '10 #3

Expert Mod 5K+
P: 9,731
Lyasta, you didn't actually state that you were having problems with the "WITH" section of the didn't even post the "WITH" section.

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

Aug 10 '10 #4

P: 4
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...
Aug 10 '10 #5

Expert Mod 5K+
P: 9,731
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.

Aug 10 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.