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?
When I check the database, the column "randomKey"- I see no code for update in database, how are you updating the database ?DataRowin yourDataTable(all in-memory representations of your data) - you're not yet storing it back to the database!DataRow- in memory (RAM) - but NOT in the database table. Check out something like this basic ADO.NET tutorial to study the basics of accessing a database using "raw" ADO.NET