Hi,
In one of the tasks, we are using sqlbulkcopy class of .net with three parameters - source db info, destination db info, query to be used to transfer data.
We are trying to see if we can get a count of the number of rows that are actually transmitted by the above command. Is there any way to do that? sqlbulkcopy class does not seem to have any attribute that would give this information. Is there any direct or indirect way?
Thanks in advance
sb
GAurav KukarPosted Dec 27, 2010, 2:07 AM
Hi Mr. Dwivendi,
Greetings!
I'm using SQlbulkcopy..and I want to detect how many rows have been successfully / is the opeartion have been executed successfully? How could i do that.. please eleborate with an example and also After insert trigger is not beenm executed attached to Destination atable.. can you please help me this to get me through with this problem...
Code:
private string strConenctionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString.ToString();
public void SaveBulkRequest(DataTable dtRequests)
{
using (SqlConnection con = new SqlConnection(strConenctionString))
{
using (SqlBulkCopy copy = new SqlBulkCopy(strConenctionString, SqlBulkCopyOptions.FireTriggers))
{
copy.ColumnMappings.Add(0, 2); //SubjectLine
copy.ColumnMappings.Add(1, 3); //RequestDescription
copy.ColumnMappings.Add(2, 4); //RequestTypeID
copy.ColumnMappings.Add(3, 5); //PriorityID
copy.ColumnMappings.Add(4, 11); //ErrorLogFile
copy.ColumnMappings.Add(6, 6); //Client ID
copy.DestinationTableName = "tblRequestDetail";
con.Open();
copy.WriteToServer(dtRequests);
Int32 roesAffected= copy.NotifyAfter;
}
}
Thanks
Gaurav Kukar
Blocked AccountPosted Jul 28, 2008, 1:39 AM
U can do this by using the SqlRowsCopied event with its SqlRowsCopiedEventArgs.RowsCopied property.
Happy Coding!!