Link to home
Start Free TrialLog in
Avatar of gouber
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;Data Source=(local);Initial Catalog=BoulderLodging;User Id=boulderlodging;Password=lodge4rent");
                  OleDbCommand cmd = new OleDbCommand("insert_deal", cn);
                  cmd.CommandType = CommandType.StoredProcedure;

                  cmd.Parameters.Add("@hotel_id", System.Data.OleDb.OleDbType.BigInt).Value = int.Parse(DropDownList1.SelectedItem.Value);
                  cmd.Parameters.Add("@deal_price",System.Data.OleDb.OleDbType.VarChar, 50).Value = deal_price.Text;
                  cmd.Parameters.Add("@deal_title", System.Data.OleDb.OleDbType.VarChar, 50).Value = deal_title.Text;
                  cmd.Parameters.Add("@deal_avail", System.Data.OleDb.OleDbType.VarChar, 350).Value = deal_avail.Text;
                  cmd.Parameters.Add("@deal_desc", System.Data.OleDb.OleDbType.VarChar, 1500).Value = deal_desc.Text;

                  cmd.ExecuteNonQuery();
                  cmd.Dispose();

                  string commandText = "Update hotels Set great_deals=1 Where hotel_id ="+int.Parse(DropDownList1.SelectedItem.Value);
                  OleDbCommand cmd2 = new OleDbCommand(commandText, cn);
                  cmd2.ExecuteNonQuery();

                  cmd.Dispose();
                  cn.Close();

                  Response.Redirect("index.aspx");
ASKER CERTIFIED SOLUTION
Avatar of Shriraj
Shriraj

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gouber
gouber

ASKER

I guess it is just the holidays creeping up on me.  There is no way I can focus at work :S.  That was part of the prob.  I guess that there are just some insert errors.  I cant believe that I took out the open connection.  Oh well.

Thanks,
Travis