Re: problem in updating DB using console application
- From: zacks@xxxxxxxxxxxxxxxxxxxxxxxx
- Date: Mon, 11 Jun 2007 07:46:01 -0700
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();
.
- Follow-Ups:
- Re: problem in updating DB using console application
- From: Claudia Fong
- Re: problem in updating DB using console application
- References:
- problem in updating DB using console application
- From: Claudia Fong
- problem in updating DB using console application
- Prev by Date: problem in updating DB using console application
- Next by Date: Re: Newbie: API function call with array pointer as argument
- Previous by thread: problem in updating DB using console application
- Next by thread: Re: problem in updating DB using console application
- Index(es):