Re: problem in updating DB using console application

Tech-Archive recommends: Speed Up your PC by fixing your registry



On Jun 11, 10:33 am, Claudia Fong <cdolphi...@xxxxxxxxxxx> wrote:
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);
}

Instead of:
SqlDataReader dataReader = cnn1Command.ExecuteReader();

use:

cnn1Command.ExecuteNonQuery();

.