I have an application where I need to store a value in a column. The value is a string in the code and the column data type is nvarchar.
foreach (DataRow row in dt.Rows)
{
//Generate a random length for randomKey range between 3 and 6 characters
Random randKey = new Random();
int randKeyLength = randKey.Next(3, 6);
//calculate randomKeyString
String randomKeyString = md5Prepare.gen_randomKeyString(randKeyLength);
//add randomKeyString to database
row["randomKey"] = randomKeyString;
}
When I check the database, the column “randomKey” is unchanged. What is wrong here?
You didn’t call any Commit methods on
DataRoworDataTable.You need the
DataAdapterandDataSetto actually update database.