473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SQL Connection problems

I have an app that uses SQL with access. I've been fine through the whole thing until I tried using the UPDATE command. When it gets to ExecuteNonQuery() it tells me that there is no open connection. A few lines before it though I can access the database. I went through the query builder and it generated an update statement. Where am I going wrong? Here's my code:

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT Count FROM Choices WHERE Title = '" + title + "' AND Choice = '" + choice + "'";
oleDbDataAdapter1.Fill(dataSet1);

DataTable dataTable = dataSet1.Tables[0];

int count = Int32.Parse(dataTable.Rows[0][4].ToString());
count++;

oleDbDataAdapter1.UpdateCommand.CommandText = "UPDATE Choices SET Count = '" + count.ToString() + "' WHERE Title = '" + title + "' AND Choice = '" + choice + "'";
oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery();
Nov 15 '05 #1
2 1327
If my memory serves me right, the Fill command opens a connection receives
the data and immediatly closes the connection.

You have to reopen the connection, execute, and close it manually.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2
"=?Utf-8?B?RXJpYw==?=" <an*******@discussions.microsoft.com> wrote in
news:C2**********************************@microsof t.com:
I have an app that uses SQL with access. I've been fine through the
whole thing until I tried using the UPDATE command. When it gets to
ExecuteNonQuery() it tells me that there is no open connection. A few
lines before it though I can access the database. I went through the
query builder and it generated an update statement. Where am I going
wrong? Here's my code:


Fill opens the Connection by its own.

for the UpdateCommand you can do something like this:

try
{
oleDbDataAdapter1.UpdateCommand.Connection.Open();
oleDbDataAdapter1.UpdateCommand.ExecuteNonQuery();
}
catch(Exception e)
{
}
finally
{
oleDbDataAdapter1.UpdateCommand.Connection.Close() ;
}

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cliff Cooley | last post by:
Can anybody suggest what may be causing the following problem ? I have an ASP script that opens a connection to an Oracle database using a DSN connection string, such as : Set dbConn=...
8
by: Peter Larsson | last post by:
Hi there, I've recently developed a VBA-program in Excel that fetches and presents data from a distant Access database over a wireless peer-to-peer network (both computers running Win XP Pro)....
9
by: mcbill20 | last post by:
Hello all. I just installed Oracle 10g developer tools on a machine running XP Pro and Office XP. Before this I had just the Oracle 9 client installed. I the previous configuration, I was able to...
2
by: Jim Heavey | last post by:
How do I set up a Connection Pool? How can I look on the server and see how many connections are being used by my application? I am pretty sure that my application must be leaving connections...
10
by: Daniel Fernandes | last post by:
Hi there Let's say due to several reasons I have an ASP.Net application that has a database access class that stores a database connection in a shared member : public class dataaccess ...
7
by: mfeingold | last post by:
I am working on a system, which among other things includes a server and a ..net control sitting in an html page and connected to the server. I ran into a couple of problems, you guys might have...
26
by: Rajeev Tipnis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en- us;819450 Questions: 1) Is this patch (fix) applicable to the .NET 1.1 Framework as well? That is, if we have Framework 1.1 (On...
4
by: Susan Baker | last post by:
PHP Newbie here - I apologize if any of my questions appear daft or obvious ... Does PHP (or maybe the web server - Apache in my case), support (database) connection pooling?. It seems terribly...
17
by: Alan Silver | last post by:
Hello, I have a generic method in a utility class that grabs an sqldatareader and returns it. Due to the fact that (AFAIK), you can't close the database connection before you've read the data,...
4
by: Fred Zuckerman | last post by:
I have a A2K database that includes some linked tables (these links are SQL views). Sometimes there are "issues" with the SQL server and the users receive a timeout error whenever they try to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.