473,406 Members | 2,847 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,406 software developers and data experts.

C# Dataadapter.Update not working for Insert Command - No Errors!

I'm writing a little app to get data from a CSV file generated everyday by a vendor and insert it into a Table in our SQL Server database. I can get the data fine, and I can easily merge it with another dataset I pull from the existing table (which is exactly the same except for an Identity Column as PK).

When I call SqlDataAdapter.Update, no error is generated, but it makes no changes as well. I have one row present in the Database and can use DataAdapter.Update to delete it just fine. It just won't insert.

Please Help! Code below:

Expand|Select|Wrap|Line Numbers
  1. using (OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\MyPath\\;Extended Properties='text;HDR=Yes;FMT=Delimited'"))
  2.             {
  3.                 string sql = "SELECT * from MyCSV.csv";
  4.                 OleDbDataAdapter csvRdr = new OleDbDataAdapter(sql, cn);
  5.                 DataSet ds = new DataSet();
  6.  
  7.                 cn.Open();
  8.  
  9.                 try
  10.                 {
  11.  
  12.                     csvRdr.Fill(ds, "Table");
  13.                     cn.Close();
  14.                     using (SqlConnection cnn = new SqlConnection("Data Source=DB;Initial Catalog=XX;User ID=usr;Password=pwd"))
  15.                     {
  16.                         string sql_2 = "Select * from DBTable";
  17.                         SqlDataAdapter da = new SqlDataAdapter(sql_2, cnn);
  18.                         SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(da);
  19.                         DataSet ds2 = new DataSet();
  20.                         da.TableMappings.Add("DBTable", "Table");
  21.                         Console.WriteLine(sql_2);
  22.                         cnn.Open();
  23.                         da.Fill(ds2, "Table");
  24.                         ds2.Merge(ds.Tables["Table"]);
  25.                         ds2.AcceptChanges();
  26. //This works              ds2.Tables["Table"].Rows[0].Delete();
  27. //Looks Fine              Console.Write(ds2.GetXml()); 
  28.                         da.Update(ds2, "Table");
  29.                         cnn.Close();
  30.                     }
  31.               }
  32.        )
Thanks.

-Mike
Aug 21 '07 #1
0 1914

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

Similar topics

5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
3
by: Larry Woods | last post by:
I have a datagrid that is carrying all fields of a record...except one. Now I want to update the underlying database via a dataadapter. The update is working but the field that is "left out" is...
13
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an...
8
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
1
by: Franklin M. Gauer III | last post by:
In VS2003 I used to be able to drag a SQL Server table from Server Explorer onto my webservice (in design mode) and it would automatically create a DataAdapter for me. This doesn't work in VS2005...
2
by: Franklin M. Gauer III | last post by:
I create a simple DATAADAPTER in a webservice project. It creates the UPDATE, INSERT, DELETE commands for me - no problem. In vS2005 it creates these commands as RESOURCES in the RESX file (i.e....
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
3
by: Rich | last post by:
What is the diffeence bewtween a dataAdapter.InsertCommand and dataAdapter.SelectCommand (and dataAdapter.UpdateCommand for that matter)? Dim da As SqlDataAdapter conn.Open da.SelectCommand =...
2
by: BobLewiston | last post by:
I can read in an SQL table ("Person.Contact") from AdventureWorks and step through it one row at a time, but when I try to save a record, either one I'm inserting or one I'm editting, I get the...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.