Dataset ds = GetYourDataFromTable1
try
{
Create connection
Create command
AddParameters to the command (column1, column2, column3)
SqlTransaction trans;
trans = connection.BeginTransaction
String () split;
foreach (datarow row in ds.tables[0].rows) {
split = String.Split(row["column1"].ToString, "-");
if (split.Length == 3)
command.Execute()
}
trans.Commit
Catch Exception e
{
trans.Rollback
}
I would do it via stored procedure with three parameters...or, if the database is Microsoft SQL Server then single parameter xml type with column1 from the first table and doing everything in the database with single insert statement.
The above code is for going 1 for 1
If this helps, accept the solution so others may find it. Thank you.
UPDATE t2
SET
alldetails_cheque = t1.chequeno
FROM
table1 t1
INNER JOIN table2 ON t1.id=t2.id and t1.name=t2.name
where t1.adviceno is null
Single update for both conditions assuming SP with parameters @id, @chequeNo and @adviceNO
UPDATE t2
SET
alldetails_cheque = CASE WHEN ISNULL(@adviceNO, '') = '' THEN t1.chequeno ELSE alldetails_cheque END,
adviceno = CASE WHEN ISNULL(@chequeno, '') = '' THEN t1.adviceNO ELSE adviceno END
FROM
table1 t1
INNER JOIN table2 ON t1.id=t2.id and t1.name=t2.name
WHERE
t2.id = @id