Hi Everyone,
I am trying to read a large table and populate another table. I need to read records in batches of 50 and send it to a table receiving it. I have the following code snippet and it works fine. But I also have another need to update the source table to mark records that we read and sent across. Instead of updating the source table column record by record I want to update the whole batch of 50 that was read and sent. The problem I have is when I try to update record by record the SQL statement updates the first record and fails after that. The other problem I have is to construct SQL string dynamically with the IN CLAUSE. How do I do this? Please see the code below. BTW I am new to the .NET world so I kinda new.
Appreciate any help
Thanks
Surkum
rrn_num.Add(drOne.GetInt32(0) <--------------- this is the relative record number of the records being read. I collect them in an array
i += 1;
if (i % 50 == 0)
{
cust_name = (string[])custname.ToArray(typeof(string));
customer = (string[])cust.ToArray(typeof(string));
city = (string[])cust_city.ToArray(typeof(string));
state = (string[])cust_state.ToArray(typeof(string));
zip = (string[])cust_zip.ToArray(typeof(string));
//close the existing connection and re-open a
// new
dataConnection.Close();
dataConnection.ConnectionString = DbLocation;
SqlCommand cmdxxx = new SqlCommand();
cmdxxx.Connection = dataConnection;
dataConnection.Open();
// How do I dynamically construct this string with
// the IN CLAUSE. IT HAS TO BE SOMETHING LIKE
UPDATE CUSTOMER _MASTER_SOURCE SET ON_TABLE = 1
WHERE RECORD_ID IN (1.24.35.45.50)
// Update the pushed customer data so only new customer
//data will be pushed on the next push
cmdxxx.CommandText = "UPDATE
CUSTOMER_MASTER_SOURCE SET ON_TABLE =
1 WHERE RECORD_ID IN....... ;
SqlDataReader drxxx = cmdxxx.ExecuteReader();
}