Solved

C# SQL Database Update question

Posted on 2003-11-25
2
338 Views
Last Modified: 2010-04-16
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");
0
Comment
Question by:gouber
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
Shriraj earned 130 total points
ID: 9821296
i Don't think that you don't know this, but you forget to open Sql Connection.

add,
cn.Open();

before  cmd.ExecuteNonQuery();

If this not your question, i am really sorry for this answer.
0
 
LVL 1

Author Comment

by:gouber
ID: 9821334
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
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question