473,654 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataAdapter not performing update

Any idea why the database table is not being updated with the contents of the excel file loaded into the dataset? Any help is appreciated!

// load database table, shell only
string cnString = "DSN=XXX D5200";
OdbcConnection myConnection = new OdbcConnection( cnString);
OdbcDataAdapter da = new OdbcDataAdapter ("select * from DB where 1=2;", myConnection);
DataSet ds = new DataSet();
da.Fill(ds, "ccginput") ;

// load excel file into dataset
string strCnExcel = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
"Data Source=" + fPath + ";" +
"Extended Properties=Exce l 8.0;";
OleDbConnection objConn = new OleDbConnection (strCnExcel);
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("S ELECT * FROM [sheet1$]", objConn);
OleDbDataAdapte r objAdapter1 = new OleDbDataAdapte r();
objAdapter1.Sel ectCommand = objCmdSelect;
objAdapter1.Fil l(ds, "ccginput") ;

// update database with contents of dataset
da.AcceptChange sDuringFill=tru e;
da.Update(ds,"c cginput");
Nov 16 '05 #1
2 1943
Chris,
1) You will probably get better answers in
microsoft.publi c.dotnet.framew ork.adonet.
2) Set AcceptChangesDu ringFill to false when filling from the Excel file
otherwise
the RowStates will all be unchanged and there will be nothing to
update.
3) You aren't defining Delete, Insert, or Update commands for the
DataAdapter anywhere
in this code so there are no command to insert, etc into the Table.

Ron Allen
"Chris Fink" <Ch*******@disc ussions.microso ft.com> wrote in message
news:67******** *************** ***********@mic rosoft.com...
Any idea why the database table is not being updated with the contents of the excel file loaded into the dataset? Any help is appreciated!
// load database table, shell only
string cnString = "DSN=XXX D5200";
OdbcConnection myConnection = new OdbcConnection( cnString);
OdbcDataAdapter da = new OdbcDataAdapter ("select * from DB where 1=2;", myConnection); DataSet ds = new DataSet();
da.Fill(ds, "ccginput") ;

// load excel file into dataset
string strCnExcel = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
"Data Source=" + fPath + ";" +
"Extended Properties=Exce l 8.0;";
OleDbConnection objConn = new OleDbConnection (strCnExcel);
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("S ELECT * FROM [sheet1$]", objConn); OleDbDataAdapte r objAdapter1 = new OleDbDataAdapte r();
objAdapter1.Sel ectCommand = objCmdSelect;
objAdapter1.Fil l(ds, "ccginput") ;

// update database with contents of dataset
da.AcceptChange sDuringFill=tru e;
da.Update(ds,"c cginput");

Nov 16 '05 #2
Chris Fink wrote:
Any idea why the database table is not being updated with the contents of
the excel file loaded into the dataset? Any help is appreciated!

// load database table, shell only
string cnString = "DSN=XXX D5200";
OdbcConnection myConnection = new OdbcConnection( cnString);
OdbcDataAdapter da = new OdbcDataAdapter ("select * from DB where 1=2;",
myConnection); DataSet ds = new DataSet();
da.Fill(ds, "ccginput") ;

// load excel file into dataset
string strCnExcel = "Provider=Micro soft.Jet.OLEDB. 4.0;" +
"Data Source=" + fPath + ";" +
"Extended Properties=Exce l 8.0;";
OleDbConnection objConn = new OleDbConnection (strCnExcel);
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("S ELECT * FROM [sheet1$]",
objConn); OleDbDataAdapte r objAdapter1 = new OleDbDataAdapte r();
objAdapter1.Sel ectCommand = objCmdSelect;
objAdapter1.Fil l(ds, "ccginput") ;

// update database with contents of dataset
da.AcceptChange sDuringFill=tru e;
da.Update(ds,"c cginput");


Seems like what you're doing is first filling ds with contents from a table,
then you redefine ds and load data from a spreadsheet and then suddenly you
expect the spreadsheet data to update the sql table ?

I think what you need is two Datasets and then you want to insert rows from
one to the other.
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2246
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 DataTable first and I then want to roll through the DataTable while in memory checking for errors and then commit the rows to my database table (btw this is in ASP.NET). Is it possible to have data in a datable before attaching at DataAdapter? I'm a...
2
4240
by: hch | last post by:
dataAdapter.Update(data, "TableName") won’t work! I was about to deploy my first website on the Internet only to discover that the dataAdapter.Update() throws the Server Error in the third underline. It was working fine before. ConnectionString in Web.config: ----------------------------------------- <?xml version="1.0" encoding="utf-8" ?> <configuration>
6
1576
by: Geoff Pennington | last post by:
I have a class method that returns a DataAdapter. I want to access the table(s) contained in the DataAdapter. Of course, accessing the DataSets would be good enough, because I could get the tables from there. I can't find a way to do this. Am I missing something? Much obliged.
13
2080
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 OleDbCommand with an SQL String and the connection it has a DataAdapter with the command then it fills the DataSet's DataTable with the streamed data.
8
2689
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. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
7
1799
by: Max | last post by:
I've included the needed tables in the DataSource. Those tables that are bound to controls I can workwith. But how do you get access to the DataAdaptors that are not bound? me.Dataset1.table is a table with no Insert or Update methods. pll.DataSet1.table has the Row, ChangeEvent, and ChangeEventHandler. It seems like it should be fairly straight forward to use the DataAdapter without binding it to a control. How do you do this?
6
13991
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 = conn da.UpdateCommand.CommandText = "Update tbl1 set fld1 = 'test' where ID = 1" da.Update(tblx) '--tblx/tbl1 not getting updated here.
2
4568
by: Rich | last post by:
Hello, Is there a way to capture the Records Affected count when performing a table Update on a Sql Server table using a DataAdapter? How is this done? Thanks, Rich
3
12503
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 = New SqlCommand da.SelectCommand.Connectoin = conn da.SelectCommand.CommandType = Command.Text da.SelectCommand.CommandText = "insert Into tbl1 Select * from tbl2" da.SelectCommand.ExecuteNonQuery
0
8372
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8814
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.