473,396 Members | 1,938 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,396 software developers and data experts.

Why SqlDataAdapter doesn't save the changes I made in a cell to DB

The string test = 'Exp'. I verified in Debug mode that test has 'Exp' in the
first line and the 2nd line of code. Showing that
dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] has the proper changed
text from null string to 'Exp'. However, the numOfRows shows 0 after
execution. I exit that form and re-enter and the 'Exp' is not showing on the
form nor the database. Can someone tell me what I'm doing wrong here?
Thanks, Alpha

dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] = test;
test = dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] .ToString();
dsVehicle.AcceptChanges();
conVeh.Open();
int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
conVeh.Close();
Nov 17 '05 #1
7 1336
This line:
dsVehicle.AcceptChanges();
sets the current RowState of all the rows to unchanged. So the dataAdapter
sees no changed or new rows, or deleted rows.
make the AcceptChanges call AFTER you have performed your update.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alpha" wrote:
The string test = 'Exp'. I verified in Debug mode that test has 'Exp' in the
first line and the 2nd line of code. Showing that
dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] has the proper changed
text from null string to 'Exp'. However, the numOfRows shows 0 after
execution. I exit that form and re-enter and the 'Exp' is not showing on the
form nor the database. Can someone tell me what I'm doing wrong here?
Thanks, Alpha

dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] = test;
test = dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] .ToString();
dsVehicle.AcceptChanges();
conVeh.Open();
int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
conVeh.Close();

Nov 17 '05 #2
Actually, there is no need to call AcceptChanges after the update. The
Update method will do this itself after it is done updating.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:45**********************************@microsof t.com...
This line:
dsVehicle.AcceptChanges();
sets the current RowState of all the rows to unchanged. So the dataAdapter
sees no changed or new rows, or deleted rows.
make the AcceptChanges call AFTER you have performed your update.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alpha" wrote:
The string test = 'Exp'. I verified in Debug mode that test has 'Exp' in
the
first line and the 2nd line of code. Showing that
dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] has the proper
changed
text from null string to 'Exp'. However, the numOfRows shows 0 after
execution. I exit that form and re-enter and the 'Exp' is not showing on
the
form nor the database. Can someone tell me what I'm doing wrong here?
Thanks, Alpha

dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] = test;
test = dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] .ToString();
dsVehicle.AcceptChanges();
conVeh.Open();
int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
conVeh.Close();

Nov 17 '05 #3
Thank you. That works that the dataset is showing HasChanges to be true.
However, now I'm getting the following error when code execute the Update
statement
int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
Error:
Dynamic SQL generation is not supported against multiple base tables.

Can you see whati I"m doing wrong here? Thanks, Alpha

My code for SQLCommandBuilder:

string strSel = "SELECT [VID], [SchID], [ScheduleName], [VName], [Make],
[Model], [Year], [VIN]," +
" [DMVLicense], [DMVExpirationDate], [DOTRegistration],
[DOTExpirationDate], [LastServiceDate]," +
" [LastServiceOdometer], [LastOdometerReading], [LastOdometerDate] " +
" FROM [VMS].[dbo].[VehDetail] left outer join [VMS].dbo.Schedule " +
" on [ExtSchID] = [SchID] order by [VName]";
sdaVehicle.SelectCommand = new SqlCommand(strSel, conVeh);
sqlCB = new SqlCommandBuilder(sdaVehicle);
conVeh.Open();
sdaVehicle.Fill(dsVehicle, "VehDetail");
conVeh.Close();

dsVehicle.Tables["VehDetail"].PrimaryKey =
new DataColumn[]
{
dsVehicle.Tables["VehDetail"].Columns["VID"]
};
"Peter Bromberg [C# MVP]" wrote:
This line:
dsVehicle.AcceptChanges();
sets the current RowState of all the rows to unchanged. So the dataAdapter
sees no changed or new rows, or deleted rows.
make the AcceptChanges call AFTER you have performed your update.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alpha" wrote:
The string test = 'Exp'. I verified in Debug mode that test has 'Exp' in the
first line and the 2nd line of code. Showing that
dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] has the proper changed
text from null string to 'Exp'. However, the numOfRows shows 0 after
execution. I exit that form and re-enter and the 'Exp' is not showing on the
form nor the database. Can someone tell me what I'm doing wrong here?
Thanks, Alpha

dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] = test;
test = dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] .ToString();
dsVehicle.AcceptChanges();
conVeh.Open();
int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
conVeh.Close();

Nov 17 '05 #4
You can't update the table, if the query had a join in it.

You can circumvent this by either modifying the select command's sql before
doing the update, or by writing your own update/insert/delete commands.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Thank you. That works that the dataset is showing HasChanges to be true.
However, now I'm getting the following error when code execute the Update
statement
> int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");

Error:
Dynamic SQL generation is not supported against multiple base tables.

Can you see whati I"m doing wrong here? Thanks, Alpha

My code for SQLCommandBuilder:

string strSel = "SELECT [VID], [SchID], [ScheduleName], [VName], [Make],
[Model], [Year], [VIN]," +
" [DMVLicense], [DMVExpirationDate], [DOTRegistration],
[DOTExpirationDate], [LastServiceDate]," +
" [LastServiceOdometer], [LastOdometerReading], [LastOdometerDate] " +
" FROM [VMS].[dbo].[VehDetail] left outer join [VMS].dbo.Schedule " +
" on [ExtSchID] = [SchID] order by [VName]";
sdaVehicle.SelectCommand = new SqlCommand(strSel, conVeh);
sqlCB = new SqlCommandBuilder(sdaVehicle);
conVeh.Open();
sdaVehicle.Fill(dsVehicle, "VehDetail");
conVeh.Close();

dsVehicle.Tables["VehDetail"].PrimaryKey =
new DataColumn[]
{
dsVehicle.Tables["VehDetail"].Columns["VID"]
};
"Peter Bromberg [C# MVP]" wrote:
This line:
dsVehicle.AcceptChanges();
sets the current RowState of all the rows to unchanged. So the
dataAdapter
sees no changed or new rows, or deleted rows.
make the AcceptChanges call AFTER you have performed your update.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alpha" wrote:
> The string test = 'Exp'. I verified in Debug mode that test has 'Exp'
> in the
> first line and the 2nd line of code. Showing that
> dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] has the proper
> changed
> text from null string to 'Exp'. However, the numOfRows shows 0 after
> execution. I exit that form and re-enter and the 'Exp' is not showing
> on the
> form nor the database. Can someone tell me what I'm doing wrong here?
> Thanks, Alpha
>
> dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] = test;
> test = dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"]
> .ToString();
> dsVehicle.AcceptChanges();
> conVeh.Open();
> int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
> conVeh.Close();

Nov 17 '05 #5
Thank you very much. That makes a lot of sense. I will work on a update
statement for this. Thanks a lot, Alpha

"Marina" wrote:
You can't update the table, if the query had a join in it.

You can circumvent this by either modifying the select command's sql before
doing the update, or by writing your own update/insert/delete commands.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Thank you. That works that the dataset is showing HasChanges to be true.
However, now I'm getting the following error when code execute the Update
statement
> int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");

Error:
Dynamic SQL generation is not supported against multiple base tables.

Can you see whati I"m doing wrong here? Thanks, Alpha

My code for SQLCommandBuilder:

string strSel = "SELECT [VID], [SchID], [ScheduleName], [VName], [Make],
[Model], [Year], [VIN]," +
" [DMVLicense], [DMVExpirationDate], [DOTRegistration],
[DOTExpirationDate], [LastServiceDate]," +
" [LastServiceOdometer], [LastOdometerReading], [LastOdometerDate] " +
" FROM [VMS].[dbo].[VehDetail] left outer join [VMS].dbo.Schedule " +
" on [ExtSchID] = [SchID] order by [VName]";
sdaVehicle.SelectCommand = new SqlCommand(strSel, conVeh);
sqlCB = new SqlCommandBuilder(sdaVehicle);
conVeh.Open();
sdaVehicle.Fill(dsVehicle, "VehDetail");
conVeh.Close();

dsVehicle.Tables["VehDetail"].PrimaryKey =
new DataColumn[]
{
dsVehicle.Tables["VehDetail"].Columns["VID"]
};
"Peter Bromberg [C# MVP]" wrote:
This line:
dsVehicle.AcceptChanges();
sets the current RowState of all the rows to unchanged. So the
dataAdapter
sees no changed or new rows, or deleted rows.
make the AcceptChanges call AFTER you have performed your update.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alpha" wrote:

> The string test = 'Exp'. I verified in Debug mode that test has 'Exp'
> in the
> first line and the 2nd line of code. Showing that
> dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] has the proper
> changed
> text from null string to 'Exp'. However, the numOfRows shows 0 after
> execution. I exit that form and re-enter and the 'Exp' is not showing
> on the
> form nor the database. Can someone tell me what I'm doing wrong here?
> Thanks, Alpha
>
> dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] = test;
> test = dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"]
> .ToString();
> dsVehicle.AcceptChanges();
> conVeh.Open();
> int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
> conVeh.Close();


Nov 17 '05 #6
Ron
You can't use a CommandBuilder when the Select query has table joins. It only
works for single tables, and quite frankly it is more efficient to write the
update command yourself even if you work with a single table.

"Marina" wrote:
You can't update the table, if the query had a join in it.

You can circumvent this by either modifying the select command's sql before
doing the update, or by writing your own update/insert/delete commands.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Thank you. That works that the dataset is showing HasChanges to be true.
However, now I'm getting the following error when code execute the Update
statement
> int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");

Error:
Dynamic SQL generation is not supported against multiple base tables.

Can you see whati I"m doing wrong here? Thanks, Alpha

My code for SQLCommandBuilder:

string strSel = "SELECT [VID], [SchID], [ScheduleName], [VName], [Make],
[Model], [Year], [VIN]," +
" [DMVLicense], [DMVExpirationDate], [DOTRegistration],
[DOTExpirationDate], [LastServiceDate]," +
" [LastServiceOdometer], [LastOdometerReading], [LastOdometerDate] " +
" FROM [VMS].[dbo].[VehDetail] left outer join [VMS].dbo.Schedule " +
" on [ExtSchID] = [SchID] order by [VName]";
sdaVehicle.SelectCommand = new SqlCommand(strSel, conVeh);
sqlCB = new SqlCommandBuilder(sdaVehicle);
conVeh.Open();
sdaVehicle.Fill(dsVehicle, "VehDetail");
conVeh.Close();

dsVehicle.Tables["VehDetail"].PrimaryKey =
new DataColumn[]
{
dsVehicle.Tables["VehDetail"].Columns["VID"]
};
"Peter Bromberg [C# MVP]" wrote:
This line:
dsVehicle.AcceptChanges();
sets the current RowState of all the rows to unchanged. So the
dataAdapter
sees no changed or new rows, or deleted rows.
make the AcceptChanges call AFTER you have performed your update.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alpha" wrote:

> The string test = 'Exp'. I verified in Debug mode that test has 'Exp'
> in the
> first line and the 2nd line of code. Showing that
> dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] has the proper
> changed
> text from null string to 'Exp'. However, the numOfRows shows 0 after
> execution. I exit that form and re-enter and the 'Exp' is not showing
> on the
> form nor the database. Can someone tell me what I'm doing wrong here?
> Thanks, Alpha
>
> dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] = test;
> test = dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"]
> .ToString();
> dsVehicle.AcceptChanges();
> conVeh.Open();
> int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
> conVeh.Close();


Nov 17 '05 #7
Thank you.

"Ron" wrote:
You can't use a CommandBuilder when the Select query has table joins. It only
works for single tables, and quite frankly it is more efficient to write the
update command yourself even if you work with a single table.

"Marina" wrote:
You can't update the table, if the query had a join in it.

You can circumvent this by either modifying the select command's sql before
doing the update, or by writing your own update/insert/delete commands.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Thank you. That works that the dataset is showing HasChanges to be true.
However, now I'm getting the following error when code execute the Update
statement
> > int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
Error:
Dynamic SQL generation is not supported against multiple base tables.

Can you see whati I"m doing wrong here? Thanks, Alpha

My code for SQLCommandBuilder:

string strSel = "SELECT [VID], [SchID], [ScheduleName], [VName], [Make],
[Model], [Year], [VIN]," +
" [DMVLicense], [DMVExpirationDate], [DOTRegistration],
[DOTExpirationDate], [LastServiceDate]," +
" [LastServiceOdometer], [LastOdometerReading], [LastOdometerDate] " +
" FROM [VMS].[dbo].[VehDetail] left outer join [VMS].dbo.Schedule " +
" on [ExtSchID] = [SchID] order by [VName]";
sdaVehicle.SelectCommand = new SqlCommand(strSel, conVeh);
sqlCB = new SqlCommandBuilder(sdaVehicle);
conVeh.Open();
sdaVehicle.Fill(dsVehicle, "VehDetail");
conVeh.Close();

dsVehicle.Tables["VehDetail"].PrimaryKey =
new DataColumn[]
{
dsVehicle.Tables["VehDetail"].Columns["VID"]
};
"Peter Bromberg [C# MVP]" wrote:

> This line:
> dsVehicle.AcceptChanges();
> sets the current RowState of all the rows to unchanged. So the
> dataAdapter
> sees no changed or new rows, or deleted rows.
> make the AcceptChanges call AFTER you have performed your update.
> Peter
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "Alpha" wrote:
>
> > The string test = 'Exp'. I verified in Debug mode that test has 'Exp'
> > in the
> > first line and the 2nd line of code. Showing that
> > dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] has the proper
> > changed
> > text from null string to 'Exp'. However, the numOfRows shows 0 after
> > execution. I exit that form and re-enter and the 'Exp' is not showing
> > on the
> > form nor the database. Can someone tell me what I'm doing wrong here?
> > Thanks, Alpha
> >
> > dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"] = test;
> > test = dsVehicle.Tables["VehDetail"].Rows[prevRow]["Model"]
> > .ToString();
> > dsVehicle.AcceptChanges();
> > conVeh.Open();
> > int numOfRows = sdaVehicle.Update(dsVehicle, "VehDetail");
> > conVeh.Close();


Nov 17 '05 #8

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

Similar topics

9
by: Mika Vainio | last post by:
hi everybody, i'm working on the following problem: i need to build a 26-nary tree to save a data dictionary. every letter of the words is represented by a cell (cell has a pointer-vector cell*...
87
by: expertware | last post by:
Dear friends, My name is Pamela, I know little about CSS, but I would like to ask a question I have an image on a web page within a css layer: <DIV ID=MyLayer STYLE = "position:...
149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
3
by: Fernando | last post by:
I am having problems with updating the changes done over a DataSet to a Database. All the changes being done using the Form are stored in the Dataset, but when i decide to close the Form and open...
3
by: LP | last post by:
Hello, In the past I used SqlCommandBuilder and SqlDataAdapter .Update method to apply changes in a DataTable back to its table source in SQL Server. It worked fine when DataSet had only 1...
4
by: Mike Szanto | last post by:
I have an intranet application where some pages display large tables of editable data. I've designed the page to operate like Microsoft Access where the user can move from cell to cell and as they...
2
by: David Batt | last post by:
Hi, I need to determine when data in a datagrid bound to a dataset has changed and thus make updates accordingly. I would of thought the code below would detect when a change has been made to...
2
by: Brian Hoops | last post by:
I have a windows forms datagrid and I would like to be able to recognize when changes have been made in order to perform the update. I tried the following, which works well, but only if the user...
2
by: rockdc1981 | last post by:
I dont it is possible to put this codes together.. I want to prompt the user to save the record and at the same time have a log of audit trail. the codes work out fine separately. Code for Audit...
2
by: Matuag | last post by:
Hi All, I want to create following command buttons on a Form which users can edit. Save ( Save Changes made) Cancel ( Undo data changes) Exit ( Close form) I am using Macros for each of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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...
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.