473,395 Members | 1,502 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,395 software developers and data experts.

Help with Count function in Access - Access

21
Hi,
i used the COUNT function to return the number of rows that satisfy the conditions set. This method works but when i press the load button again, it will still gives me another same set of information. This loop never ends.

C# (VS 2005) Code :

Expand|Select|Wrap|Line Numbers
  1. string Cnt = "SELECT Count(1) FROM Module_Repair_Info WHERE StopDate = " + Date + " AND StopTime = " + Time + " AND SerialNo = '" + strSerialNumber + "'";
  2.  
  3.                                         if (Cnt != "0")
  4.                                         {
  5.  
  6.                                             string insertString = "INSERT INTO Module_Repair_Info (" +
  7.                                                                   "FailureNo, XmtrType, SerialNo, [Hardware Rev], [Software Rev], [Firmware Rev], StopDate, StopTime, Stn, Chn " +
  8.                                                                   ") VALUES (" +
  9.                                                                   "' ', '" + Model + "', '" + ModuleSerialNumber + "', '" + Hardware + "', '" + Software + "', '" + Firmware + "', '" + Date + "', '" + Time + "', '" + StationNumber + "', " + ChannelNumber +
  10.                                                                   ")";
  11.  
  12.                                             OleDbCommand myCommand = new OleDbCommand(insertString, myConn2);
  13.                                             myCommand.ExecuteNonQuery();
  14.  
  15.  
  16.                                         }
I was wondering whats wrong with this code that i had written. Pls help as i spent 2 days on this problem.

Thanks in advance!
Mar 12 '07 #1
7 1428
kenobewan
4,871 Expert 4TB
I believe that Cnt is never going to be "0". Have you displayed the value to see what is going on? Have you tried using count(*) if you want to count the number of records?
Mar 12 '07 #2
wertqt
21
hi there,
i tried using Count(*), it still gives me the same string result : "SELECT Count(*) FROM Module_Repair_Info WHERE StopDate = 01-09-2007 AND StopTime = 11:37:52 AND SerialNo = '1746060179'."

I believed that Cnt will not be "0" too but how can i get/return the number of records in this case? I wanted the result to be an integer since it is the number of rows that satisfy the conditions set.

Thanks!
Mar 12 '07 #3
kenobewan
4,871 Expert 4TB
If you want count as an integer, try storing it as an integer and testing that in your condition. Please try this and report back.
Mar 12 '07 #4
wertqt
21
i dont think im able to store it as int if i use SELECT statement. I need to use SELECT statement as there are conditions/criterias. That is y i have to use string Cnt = "SELECT .....";
Or is there another way to store it as int?
Mar 13 '07 #5
kenobewan
4,871 Expert 4TB
What happens if you use int Cnt = "Select...";? Here is an article that may reflect your concern about using int rather than string, but as long as strongly type and don't declare as object you should be ok:
A Lesson in ASP.NET/SQL Security

Good points about web security too. You may also want to use try/catch blocks.
Mar 13 '07 #6
wertqt
21
hi,
i solved the problem. i forgot to execute the SELECT statement and that is y i couldnt get the int value.

Thanks!
Mar 13 '07 #7
kenobewan
4,871 Expert 4TB
Well done :)!
Mar 14 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jim Hubbard | last post by:
I have some C# code that is supposed to wrap the defrag APIs and I am trying to convert it to VB.Net (2003). But, I keep having problems. The C# code is relatively short, so I'll post it...
21
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the...
11
by: dhnriverside | last post by:
Hi peeps Ok, so I thought I'd have a go at making a console app in VS2k5... I haven't written any windows apps for years, let alone dos apps (been web programming) and I've hit a dumb error... ...
7
by: Satish | last post by:
Hi Friends I am little confused about the shadows keyword in VB.NET could anyone explain with an example about Shadows keyword Many thanks Satish
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
6
by: troy_lee | last post by:
I am trying to count the total number of units for a given part number that have a Priority rating of 1. Based upon some research, this is what I came up with for my query. Access says that I have...
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: 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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.