How to Update Existing data by comparing lenth in C#

Posted by imomins on May 30, 2011 at 6:01 AM

 

private void mprivUpdateStockItemCodeRelatedRecord()

{

string lstrNewStockItemCode;

if (clsDatabaseConnector.gmpubstasqlconnSQLConnection.State == ConnectionState.Open)

{

clsDatabaseConnector.gmpubstasqlconnSQLConnection.Close();

}

clsDatabaseConnector.gmpubstasqlconnSQLConnection.Open();

 

//OPEN TEMPORARY CONNECTION

if (clsDatabaseConnector.gmpubstasqlconnSQLConnectionTemp.State == ConnectionState.Open)

{

clsDatabaseConnector.gmpubstasqlconnSQLConnectionTemp.Close();

}

clsDatabaseConnector.gmpubstasqlconnSQLConnectionTemp.Open();

 

string lstrQuery = "SELECT STOCKITEM_CODE FROM INV_STOCKITEM WHERE STOCKITEM_CODE <> 'NULL' ORDER BY STOCKITEM_CODE";

SqlCommand thisCommand = new SqlCommand(lstrQuery, clsDatabaseConnector.gmpubstasqlconnSQLConnection);

SqlDataReader thisReader = thisCommand.ExecuteReader();

 

while (thisReader.Read())

{

lstrNewStockItemCode = null;

string lstrOldStockItemCode = Convert.ToString(thisReader["STOCKITEM_CODE"]);

 

if (lstrOldStockItemCode != "As Per Details")

{

string[] oldSplitedCode = lstrOldStockItemCode.Split('.');

 

foreach (string splitedCode in oldSplitedCode)

{

if (splitedCode.Length == 2)

{

lstrNewStockItemCode += "0" + splitedCode + ".";

}

else if (splitedCode.Length > 2)

{

lstrNewStockItemCode += "00" + splitedCode;

}

}

 

string lstrUpdateQuery = "UPDATE INV_STOCKITEM SET STOCKITEM_CODE = '" + lstrNewStockItemCode + "' WHERE STOCKITEM_CODE = '" + lstrOldStockItemCode + "'";

lstrUpdateQuery += "; UPDATE ACC_SALES_PRICE_SETTING_CHILD SET STOCKITEM_CODE = '" + lstrNewStockItemCode + "' WHERE STOCKITEM_CODE = '" + lstrOldStockItemCode + "'";

lstrUpdateQuery += "; UPDATE INV_TRAN_CHILD SET STOCKITEM_CODE = '" + lstrNewStockItemCode + "' WHERE STOCKITEM_CODE = '" + lstrOldStockItemCode + "'";

lstrUpdateQuery += "; UPDATE INV_SL_NO_WISE_STOCK_DETAILS SET STOCKITEM_CODE = '" + lstrNewStockItemCode + "' WHERE STOCKITEM_CODE = '" + lstrOldStockItemCode + "'";

lstrUpdateQuery += "; UPDATE INV_LC_OR_WORK_ORDER_CHILD SET STOCKITEM_CODE = '" + lstrNewStockItemCode + "' WHERE STOCKITEM_CODE = '" + lstrOldStockItemCode + "'";

lstrUpdateQuery += "; UPDATE TAA_TARGET_SETTING_CHILD SET STOCKITEM_CODE = '" + lstrNewStockItemCode + "' WHERE STOCKITEM_CODE = '" + lstrOldStockItemCode + "'";

 

SqlCommand thisCommandTemp = new SqlCommand(lstrUpdateQuery, clsDatabaseConnector.gmpubstasqlconnSQLConnectionTemp);

thisCommandTemp.ExecuteNonQuery();

}

}

thisReader.Close();

clsDatabaseConnector.gmpubstasqlconnSQLConnectionTemp.Close();

clsDatabaseConnector.gmpubstasqlconnSQLConnection.Close();

}

 

 

 

 

 

mprivUpdateStockItemCodeRelatedRecord();


Categories: Personal, C#

Post a Comment

Oops!

Oops, you forgot something.

Oops!

The words you entered did not match the given text. Please try again.

You must be a member to comment on this page. Sign In or Register

0 Comments