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

DataAdapter not performing update

P: n/a
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=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fPath + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(strCnExcel);
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [sheet1$]", objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
objAdapter1.Fill(ds, "ccginput");

// update database with contents of dataset
da.AcceptChangesDuringFill=true;
da.Update(ds,"ccginput");
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Chris,
1) You will probably get better answers in
microsoft.public.dotnet.framework.adonet.
2) Set AcceptChangesDuringFill 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*******@discussions.microsoft.com> wrote in message
news:67**********************************@microsof t.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=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fPath + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(strCnExcel);
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [sheet1$]", objConn); OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
objAdapter1.Fill(ds, "ccginput");

// update database with contents of dataset
da.AcceptChangesDuringFill=true;
da.Update(ds,"ccginput");

Nov 16 '05 #2

P: n/a
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=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fPath + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(strCnExcel);
objConn.Open();
OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM [sheet1$]",
objConn); OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
objAdapter1.Fill(ds, "ccginput");

// update database with contents of dataset
da.AcceptChangesDuringFill=true;
da.Update(ds,"ccginput");


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 discussion thread is closed

Replies have been disabled for this discussion.