PC Review


Reply
Thread Tools Rate Thread

Actually, ado.net 2.0 help needed - batch update failing

 
 
andy6
Guest
Posts: n/a
 
      15th Jun 2006
I am using the following code and SQL Profiler shows no activity when I step
through the .update line. Do you see a syntax error?
Thanks!

using (SqlConnection cn = new SqlConnection(cnStr))
{
SqlCommand updCmd = new SqlCommand
("sp_web_edit_manager_update", cn);

SqlDataAdapter adpt = new SqlDataAdapter(updCmd);

updCmd.UpdatedRowSource = UpdateRowSource.None;
updCmd.Parameters.Add("@entity", SqlDbType.VarChar,10,
dtOnlyChanges.Columns[0].ColumnName);
updCmd.Parameters.Add("@edit_id", SqlDbType.Int, 4,
dtOnlyChanges.Columns[1].ColumnName);
updCmd.Parameters.Add("@edit_override", SqlDbType.VarChar, 1,
dtOnlyChanges.Columns[2].ToString());
updCmd.Parameters.Add("@biller_cd", SqlDbType.VarChar, 20,
dtOnlyChanges.Columns[3].ToString());
updCmd.Parameters.Add("@include_in_stats", SqlDbType.VarChar,
1, dtOnlyChanges.Columns[4].ToString());

adpt.UpdateCommand = updCmd;

// Set the Batch Size. 0 means all; default is 1.
adpt.UpdateBatchSize = 10;

// Send the new rows and the changed rows to the database
adpt.Update(dtOnlyChanges);

}

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
 
 
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      15th Jun 2006
probably no changed (rowstate == modified) rows in the dataset to update.

-- bruce (sqlwork.com)

"andy6" <u9025@uwe> wrote in message news:61cf9e8450e76@uwe...
>I am using the following code and SQL Profiler shows no activity when I
>step
> through the .update line. Do you see a syntax error?
> Thanks!
>
> using (SqlConnection cn = new SqlConnection(cnStr))
> {
> SqlCommand updCmd = new SqlCommand
> ("sp_web_edit_manager_update", cn);
>
> SqlDataAdapter adpt = new SqlDataAdapter(updCmd);
>
> updCmd.UpdatedRowSource = UpdateRowSource.None;
> updCmd.Parameters.Add("@entity", SqlDbType.VarChar,10,
> dtOnlyChanges.Columns[0].ColumnName);
> updCmd.Parameters.Add("@edit_id", SqlDbType.Int, 4,
> dtOnlyChanges.Columns[1].ColumnName);
> updCmd.Parameters.Add("@edit_override", SqlDbType.VarChar,
> 1,
> dtOnlyChanges.Columns[2].ToString());
> updCmd.Parameters.Add("@biller_cd", SqlDbType.VarChar, 20,
> dtOnlyChanges.Columns[3].ToString());
> updCmd.Parameters.Add("@include_in_stats",
> SqlDbType.VarChar,
> 1, dtOnlyChanges.Columns[4].ToString());
>
> adpt.UpdateCommand = updCmd;
>
> // Set the Batch Size. 0 means all; default is 1.
> adpt.UpdateBatchSize = 10;
>
> // Send the new rows and the changed rows to the database
> adpt.Update(dtOnlyChanges);
>
> }
>
> --
> Message posted via http://www.dotnetmonster.com



 
Reply With Quote
 
andy6 via DotNetMonster.com
Guest
Posts: n/a
 
      15th Jun 2006
Good catch! Thank you.

I ended up with this code.

using (SqlConnection cn = new SqlConnection(DBConnectionString))
{
using (SqlCommand updCmd = new SqlCommand
("sp_web_edit_manager_update", cn))
{
SqlDataAdapter adpt = new SqlDataAdapter(updCmd);
updCmd.CommandType = CommandType.StoredProcedure;
updCmd.CommandTimeout = Convert.ToInt32
(ConfigurationSettings.AppSettings["dbCommandTimeout"]);

updCmd.UpdatedRowSource = UpdateRowSource.None;
updCmd.Parameters.Add("@entity", SqlDbType.VarChar, 10,
dtOnlyChanges.Columns[0].ColumnName);
updCmd.Parameters.Add("@edit_id", SqlDbType.Int, 4,
dtOnlyChanges.Columns[1].ColumnName);
updCmd.Parameters.Add("@edit_override", SqlDbType.VarChar,
1, dtOnlyChanges.Columns[2].ToString());
updCmd.Parameters.Add("@biller_cd", SqlDbType.VarChar, 20,
dtOnlyChanges.Columns[3].ToString());
updCmd.Parameters.Add("@include_in_stats", SqlDbType.
VarChar, 1, dtOnlyChanges.Columns[4].ToString());

adpt.UpdateCommand = updCmd;

// Set the Batch Size. 0 means all; default is 1.
adpt.UpdateBatchSize = 0;

foreach(DataRow b in dtOnlyChanges.Rows)
{
b.SetModified();
}

cn.Open();

// send the changed rows("modified") to the database
adpt.Update(dtOnlyChanges);
}
}

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed with batch files. Chris Mitchell Windows XP Help 1 21st Jul 2008 10:08 AM
Backup batch file needed Hans Näslund Microsoft Windows 2000 8 18th Aug 2006 03:23 PM
XP Batch file needed for mapping Richard A Windows XP General 6 10th Jun 2004 03:20 AM
NEEDED: Sources of info to retrieve data off failing (failed) hard drives. Stellijer Storage Devices 1 15th Dec 2003 06:00 PM
TCP/IP Batch needed Rob Microsoft Windows 2000 Printing 0 7th Jul 2003 09:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:03 PM.