C
Claudia Fong
Hi,
I'm using console application to connect to a db and I managed to use
the SELECT statement to display records in my DB but I also need to
UPDATE some fields in my table but after I run the code below, it didn't
update the record..
Can someone tell me?
Cheers
Claudi
SqlConnection cnn1 = new SqlConnection();
cnn1.ConnectionString = "Integrated Security=SSPI;" +
"Initial Catalog=LibraryDB;" +
"Data Source= .\\SQLExpress";
try
{
cnn1.Open();
SqlCommand cnn1Command = new SqlCommand();
cnn1Command.Connection = cnn1;
cnn1Command.CommandText = "UPDATE RESERVED SET ISBN = '"
+ isbn_number + "' , UserID = '" + userID + "'";
SqlDataReader dataReader = cnn1Command.ExecuteReader();--> What should I
put in here in order the UPDATE to work?
dataReader.Close();
cnn1.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error accessing the database: " +
ex.Message);
}
Cheers!
Claudi
I'm using console application to connect to a db and I managed to use
the SELECT statement to display records in my DB but I also need to
UPDATE some fields in my table but after I run the code below, it didn't
update the record..
Can someone tell me?
Cheers
Claudi
SqlConnection cnn1 = new SqlConnection();
cnn1.ConnectionString = "Integrated Security=SSPI;" +
"Initial Catalog=LibraryDB;" +
"Data Source= .\\SQLExpress";
try
{
cnn1.Open();
SqlCommand cnn1Command = new SqlCommand();
cnn1Command.Connection = cnn1;
cnn1Command.CommandText = "UPDATE RESERVED SET ISBN = '"
+ isbn_number + "' , UserID = '" + userID + "'";
SqlDataReader dataReader = cnn1Command.ExecuteReader();--> What should I
put in here in order the UPDATE to work?
dataReader.Close();
cnn1.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error accessing the database: " +
ex.Message);
}
Cheers!
Claudi