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

Data Changes not being saved from DataAdapter

RSH
I have a simple application that is filling a dataset, importing several
rows, building an Insert Statement, then attempting to commit the changes.
No exceptions are being raised but the data is never saving and I can't
figure out why not.

This is the method that fills the dataset:
public void PopulateDataset(string strSql)

{

try

{

OleDbCommand _ObjCmd = new OleDbCommand(strSql,
(OleDbConnection)Connection);

m_LDataAdapter = new OleDbDataAdapter(_ObjCmd);

if (Connection.State == ConnectionState.Closed)

{

Connection.Open();

}

m_Dataset = new DataSet();

m_LDataAdapter.Fill(m_Dataset, "tbl");

m_DatasetInitialized = true;

BuildInsertCommand();

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

}

This method imports the row into the dataset:

public void AddRow(DataRow row)

{

if (m_DatasetInitialized == true)

{

m_Dataset.Tables[0].ImportRow(row);

}

}

This Method builds the Insert Command:

private void BuildInsertCommand()

{

if (m_DatasetInitialized == true)

{

OleDbParameter sqlParam;

OleDbCommand sqlUpdateCommand = new OleDbCommand("INSERT INTO [sheet1$]
([Group],[Category],[SearchPhrase],[CaseNumber],[TimeReceived],[SubmittedBy],[ClientNumber],[ClientName],[Status],[DateClosed],[Product],[AssignedToTech],[Detail])
VALUES(@Group,@Category,@SearchPhrase,@CaseNumber, @TimeReceived,@SubmittedBy,@ClientNumber,@ClientNa me,@Status,@DateClosed,@Product,@AssignedToTech,@D etail)",
(OleDbConnection)m_ObjConn);

sqlParam = new OleDbParameter("@Group", OleDbType.VarChar, 100, "Group");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@Category", OleDbType.VarChar, 100,
"Category");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@SearchPhrase", OleDbType.VarChar, 100,
"SearchPhrase");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@SearchPhrase", OleDbType.VarChar, 100,
"SearchPhrase");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@CaseNumber", OleDbType.VarChar, 100,
"CaseNumber");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@TimeReceived", OleDbType.VarChar, 100,
"TimeReceived");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@SubmittedBy", OleDbType.VarChar, 100,
"SubmittedBy");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@ClientNumber", OleDbType.VarChar, 100,
"ClientNumber");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@ClientName", OleDbType.VarChar, 250,
"ClientName");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@Status", OleDbType.VarChar, 250, "Status");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@DateClosed", OleDbType.VarChar, 250,
"DateClosed");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@Product", OleDbType.VarChar, 250,
"Product");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@AssignedToTech", OleDbType.VarChar, 250,
"AssignedToTech");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

sqlParam = new OleDbParameter("@Detail", OleDbType.VarChar, 1250, "Detail");

sqlParam.SourceVersion = DataRowVersion.Original;

sqlUpdateCommand.Parameters.Add(sqlParam);

m_LDataAdapter.InsertCommand = sqlUpdateCommand;

}

}

And this method attempts to save the data:

public void SaveChanges()

{

m_Dataset.AcceptChanges();

m_LDataAdapter.Update(m_Dataset, "tbl");

m_ObjConn.Close();

}

When I run the code in debugger I see the rows that were imported into the
dataset. I see that the insert Command was been added to the data adapter.
What am I missing?

Thanks so much for the help!

Ron
Jan 18 '08 #1
0 1163

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

Similar topics

32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
4
by: Claudia Fong | last post by:
Hi, I have a form where I need to display the data of a department that stores in a access db. When I first load the form it will call a function name loaddata which will get the first...
3
by: DwC | last post by:
Hi, We have a ms access database that we will be using to develop a website which would have fairly low usage levels. We have some experience with windows apps but not so much with asp.net...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
14
by: Sueffel | last post by:
Okay, I have the following scenerio: Protected Sub DelRows() Dim rw As DataRow Dim rrw As DataRow Dim DT as DataTable Dim rws() as DataRow For each rw in ds.Tables("Table1").Rows rws =...
4
by: Andrew Chalk | last post by:
I have some data in a DataSet and want to write it back to the underlying SQL Server database. Is there any simple "one-liner" way to write a dataset back to its database or do I have to go through...
15
by: Marcus | last post by:
I created a VB.Net 1.1 application that iterates through all the tables in any basic Access 2000 database passed to it and generates the same table structure in a SQL Server Express database. The...
3
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new...
7
by: Kevin | last post by:
I'm new to ADO.NET--trying to make the switch from ADO, which I've been using in my VB2005 apps up until now. Here's what I have: Sub Save_Record() Dim OldRecord as DataTable Dim NewRecord as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.