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

Problem accessing an Access database in C#

Paul Johnson
Hi,

I seem to have hit a problem when try to drag data from an Access file. I know I can do it as I've populated some combo boxes using pretty much the same code, however, the code below is returning nothing and I cannot see why!

Any help would be appreciated

Expand|Select|Wrap|Line Numbers
  1.         private void searchInformation(List<string> detail, List<bool> opts)
  2.         {
  3.             int id = 0;
  4.             string commandString = "Select TutorID from TutorNames WHERE Name = '" + detail[0] + "'";
  5.             OleDbCommand objCommand = new OleDbCommand(commandString, conn);
  6.             conn.Open();
  7.             OleDbDataReader reader = objCommand.ExecuteReader();
  8.             while (reader.Read() == true)
  9.             {
  10.                 try
  11.                 {
  12.                     id = (int)reader["TutorID"];
  13.                 }
  14.                 catch (Exception e)
  15.                 { }
  16.             }
  17.             conn.Close();
  18.  
  19.             if (id == 0)
  20.             {
  21.                 MessageBox.Show(detail[0] + " doesn't exist on the database", "Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
  22.                 return;
  23.             }
  24.             MessageBox.Show(detail[0] + " exists, ID = " + id.ToString(), "Database");
  25.  
details[0] contains the name to be searched for (directly from a TextBox). TutorID exists in the TutorNames table and for test purposes, I'm using data that I know exists.

The only thing I can think of is that there are some escape characters at the end of the text (either being passed in or in the database) - everything else seems valid.

I have tried

"Select * from TutorNames where Name = '" + details[0] + "'" to see if I can see TutorID, but nothing is being returned.

Additionally, I've tried another tack using a DataSet and DataTable in a similar way to the ways shown on MSDN, but still nothing.

Any clues would be appreciated!

Thanks

Paul
Oct 15 '11 #1
0 1207

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

Similar topics

7
by: Graham Taylor | last post by:
I've tried posting this in the 'microsoft.public.access' but I will post it here also, as I think it might be the webserver which is causing my problem. --------- I have an Access 2003 database...
5
by: kai | last post by:
Hi, All I try to block some one import my Access database tables using Access database. I used password protection, but if some one crack through my password, are there any other methods to...
0
by: vginders | last post by:
Hello, We have a legacy application which relies on an Access 97 database (upgrading is nog an option atm). As we are setting up a new server (Windows 2003), we started experiencing problems...
3
by: Suhas Vengilat | last post by:
Hi, I am facing a problem accessing SQL Server using WindowsAuthentication. One Sharepoint application development team need a webpart to access one SQL Server Database using a service account...
0
by: Tom Wild | last post by:
Hi I am creating a webform in VB.Net which connects to an Access database. I can get the webform to connect to the database fine and also to download data but when I try and update the...
3
by: Steve Teeples | last post by:
I am writing my first database application. I am unable to even get to first base because I can't seem to access the data in the database. Each time the "Fill" command is executed I get an...
3
by: watson128 | last post by:
I have a program that interrogates and modifies an Access database. When I run this program from the VB editor it runs fine. When I make the exe file and run that it crashes saying that the "Object...
3
by: Nathan Sokalski | last post by:
When I attempt to access a Microsoft Access database from my website, I recieve the following error: Server Error in '/' Application....
1
by: Co | last post by:
Hi All, I use a database that copies records to a second database (both 97) that is present on a memory stick. After I have done my code I want to remove the memory stick and use it in another...
3
by: John Dann | last post by:
We've got a VB2005 program written some time back that we're trying to do some maintenance on still from within VB2005 but now running on a Vista Business PC (which I think may be relevant to the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.