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

SQLDataAdapter Update Error

--------------------------------------------------------------------------------

I have a problem in updating certain data in an SQL table.
Hope, I have the right syntax. It accepts the commands. However, the data is
never updated.

Placed below is the code.

Thanks.

================================================== ========
mycn.Open();
myda = new SqlDataAdapter ("SELECT
lng_id,lng_clientid,str_mail_from,str_mail_to FROM web_tbl_emails", mycn);

ds = new DataSet();
myda.Fill (ds,"Table");

foreach(DataRow row in ds.Tables [0].Rows )
{
row.ItemArray.SetValue(System.DateTime.Now.ToStrin g()+1,10);
row.ItemArray.SetValue("test1",2);
row.ItemArray.SetValue("test2",3);
myda.Update (ds,"web_tbl_emails");
}
Nov 22 '05 #1
4 3008
You need to create an update command to tell the data adapter the SQL
statements to pass to the database to update the data.

....
myda.UpdateCommand = new SqlCommand();
myda.UpdateCommand.CommandText = "UPDATE web_tbl_emails SET ...";
....
foreach(DataRow row in ds.Tables [0].Rows )
{
// make your changes
}
// move the update call outside the foreach loop to update all at once:
myda.Update (ds,"web_tbl_emails");

http://msdn.microsoft.com/library/en...mmandtopic.asp

Cheers,
Steve Goodyear
Nov 22 '05 #2
You need to create an update command to tell the data adapter the SQL
statements to pass to the database to update the data.

....
myda.UpdateCommand = new SqlCommand();
myda.UpdateCommand.CommandText = "UPDATE web_tbl_emails SET ...";
....
foreach(DataRow row in ds.Tables [0].Rows )
{
// make your changes
}
// move the update call outside the foreach loop to update all at once:
myda.Update (ds,"web_tbl_emails");

http://msdn.microsoft.com/library/en...mmandtopic.asp

Cheers,
Steve Goodyear
Nov 22 '05 #3
Rob,

for this simple one you can beside writing your own update command as well
use the commandbuilder.

ds = new DataSet();
myda.Fill (ds,"Table");
SqlCommandBuilder cmb = new SqlCommandBuilder(myda);
foreach(DataRow row in ds.Tables [0].Rows )
{

..............

I hope this helps,

Cor
Nov 22 '05 #4
Rob,

for this simple one you can beside writing your own update command as well
use the commandbuilder.

ds = new DataSet();
myda.Fill (ds,"Table");
SqlCommandBuilder cmb = new SqlCommandBuilder(myda);
foreach(DataRow row in ds.Tables [0].Rows )
{

..............

I hope this helps,

Cor
Nov 22 '05 #5

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

Similar topics

0
by: JEP | last post by:
I lifted the following code directly from MSDN examples. However, the update command fails against my Northwind/SQL Server database. The code is: Private Sub cmdStart_Click(ByVal sender As...
2
by: DraguVaso | last post by:
Hi, I have a DataGrid bound to an sqlDataAdapter. When I do a SqlDataAdapter.Update, on 1 row I got a red dot with a whie exclamation mark in it, to show me there is an error, and the changes...
1
by: Steven Blair | last post by:
Hi, Here is a short decsription of my problem. I have written a dll for Database accessing. I have one method which can return a Dataset and another method which takes a Dataset and upates a...
3
by: Christoph | last post by:
I'm delving into using ADO.NET for the first time. In fact, I've never done any database work using C# at all so all of this is new to me. Please bear that in mind if I am asking stupid questions....
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...
1
by: archana | last post by:
hi all I have some doubts related to database handling in .net. I am using sqldataadapter to update and insert rows into database. What i want to know is at a time of inserting rows using...
1
by: languy | last post by:
Hi there I'm having a problem when using the SqlDataAdapter. When calling the Update(DataSet, string) method I get the following error message "String or binary data would be truncated". The...
2
by: Aaron | last post by:
Hello, The SqlDataAdapter has 4 properties of type SqlCommand, SelectCommand, UpdateCommand, DeleteCommand, and InsertCommand. Setting the SelectCommand allows the SqlDataAdapter to retrieve...
1
by: niccolem | last post by:
HI: Can someone tell me HOW to insert a automatic number after my user inserts new data from text boxes into the dataset. I keep getting this error: Cannot insert the value NULL into column 'id',...
8
by: Benniit | last post by:
Am using Vb.NET 2008 and SQL 2008. I have a problem, when the execution reaches daAdapter.Update(dtTable) then I receive this error ""String or binary data would be truncated. The statement has been...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.