473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

4
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.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
  6.  
Aug 6 '10 #1
5 4139
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
  7.  
  8. addRow("rowname") = txtName.Text
  9.  
  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
lyasta
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
  8.  
Aug 10 '10 #3
Frinavale
9,735 Expert Mod 8TB
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
Aug 10 '10 #4
lyasta
4
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...
Aug 10 '10 #5
Frinavale
9,735 Expert Mod 8TB
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
Aug 10 '10 #6

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

Similar topics

5
by: Stefan Turalski \(stic\) | last post by:
Hi, I'm wondering if there is a way to send a method parametrs by ref when DataTabel is a type of this value ? I done some sort of select over DataTable columns, just by removing them froma...
3
by: Alexander | last post by:
Hi, I am using a DataGrid and assign a DataTable as a DataSource to it: void ShowData() { DataTable myNewDataTable = new DataTable(); ... // fill table this.m_DataGrid1.DataSource =...
3
by: Mike | last post by:
Dear Group, When I add a DataTable to a Typed Dataset, and a TableAdapter to the DataTable, I am able to create methods to send updates directly to the database (GenerateDBDirectMethods),...
10
by: dauphian | last post by:
Hello, I am new to .net and am trying to build a report application that queries 4 different tables based on a id, and I need to return them in the same table for easy viewing. Basically, I...
1
by: Demetri | last post by:
I have a question / concern regarding the new suggested way of creating a data access layer in an n-tier application. Typically, a web application specifically, using the SOA (Service Oriented...
1
by: Maxwell2006 | last post by:
Hi, I am working with strongly typed datatables. What is the most efficient way to build a new DataTAble based on the result of DataTable.Select? At this point I use a foreach loop to do the...
0
by: brian.twardzik | last post by:
Hello! I'm curious, if I were to do the following: myAdapter.Fill(0, 4000, table1) myAdapter.Fill(4000, 8000, table2) Would I gather all 8000 rows of my Datasource? Would I miss any...
1
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint...
6
by: Marc | last post by:
Hi using vbnet is it possible to create a datatable from another datatable using a select query So i have a datatable1 with all data I need to create from datatable1 a new datatable2 ...
9
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.