Solved

C# SQL Database Update question

Posted on 2003-11-25
2
336 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 50
Winforms -- Capture CTRL+SHIFT+D at the form not working? 3 31
jquery + C#.net radiobuttonlist 3 45
linq, c# 8 33
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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