gouber
asked on
C# SQL Database Update question
I have the following code. It works except for the SQL UPDAT E part. I get an unhandeled exception error that says I need an open and available connection. Any help would be appreciated.
I am using access and I am using Borland C# builder to compile this if that information makes a difference.
Thanks,
Travis
private void Button1_Click(object sender, System.EventArgs e)
{
OleDbConnection cn = new OleDbConnection("Provider= sqloledb;D ata Source=(local);Initial Catalog=BoulderLodging;Use r Id=boulderlodging;Password =lodge4ren t");
OleDbCommand cmd = new OleDbCommand("insert_deal" , cn);
cmd.CommandType = CommandType.StoredProcedur e;
cmd.Parameters.Add("@hotel _id", System.Data.OleDb.OleDbTyp e.BigInt). Value = int.Parse(DropDownList1.Se lectedItem .Value);
cmd.Parameters.Add("@deal_ price",Sys tem.Data.O leDb.OleDb Type.VarCh ar, 50).Value = deal_price.Text;
cmd.Parameters.Add("@deal_ title", System.Data.OleDb.OleDbTyp e.VarChar, 50).Value = deal_title.Text;
cmd.Parameters.Add("@deal_ avail", System.Data.OleDb.OleDbTyp e.VarChar, 350).Value = deal_avail.Text;
cmd.Parameters.Add("@deal_ desc", System.Data.OleDb.OleDbTyp e.VarChar, 1500).Value = deal_desc.Text;
cmd.ExecuteNonQuery();
cmd.Dispose();
string commandText = "Update hotels Set great_deals=1 Where hotel_id ="+int.Parse(DropDownList1 .SelectedI tem.Value) ;
OleDbCommand cmd2 = new OleDbCommand(commandText, cn);
cmd2.ExecuteNonQuery();
cmd.Dispose();
cn.Close();
Response.Redirect("index.a spx");
I am using access and I am using Borland C# builder to compile this if that information makes a difference.
Thanks,
Travis
private void Button1_Click(object sender, System.EventArgs e)
{
OleDbConnection cn = new OleDbConnection("Provider=
OleDbCommand cmd = new OleDbCommand("insert_deal"
cmd.CommandType = CommandType.StoredProcedur
cmd.Parameters.Add("@hotel
cmd.Parameters.Add("@deal_
cmd.Parameters.Add("@deal_
cmd.Parameters.Add("@deal_
cmd.Parameters.Add("@deal_
cmd.ExecuteNonQuery();
cmd.Dispose();
string commandText = "Update hotels Set great_deals=1 Where hotel_id ="+int.Parse(DropDownList1
OleDbCommand cmd2 = new OleDbCommand(commandText, cn);
cmd2.ExecuteNonQuery();
cmd.Dispose();
cn.Close();
Response.Redirect("index.a
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
Travis