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

Returning one selected value from an Access DataBase in C#

Hello all!! I am coding a simulated ATM for my software eng class. I would consider myself to be an intermediate programmer, but I have run into a huge problem. I have opened and linked my database to my C# project;
however I can not get the SQL statement "Select FreeChecking from BankAccount where PIN = ..."; to return the value that is saved in the database.
HELP PLEASE! I am attaching snippets of my code

Expand|Select|Wrap|Line Numbers
  1. //--------------------------------------------------------
  2.             //This method returns one selected record from database.
  3.             //--------------------------------------------------------
  4.  
  5.             public DataTable RecordSelect(String Sql)
  6.             {
  7.  
  8.                 cmd = new OleDbCommand(Sql, conn);
  9.                 adapter = new OleDbDataAdapter(Sql, conn);
  10.                 dt = new DataTable();
  11.                 adapter.Fill(dt);
  12.                 return dt;
  13.             }
Expand|Select|Wrap|Line Numbers
  1. String sqlText = String.Format("SELECT FreeChecking FROM BankAccount2 where PIN = {0};", PIN);
  2.               dt =   db.RecordSelect(sqlText);
  3.  
  4.  
  5.  
  6.                 for (int i = 0; i < atmData.Rows.Count; i++)
  7.                 {
  8.                     try
  9.                     {
  10.                         string msg = String.Format("{0} {1} {2:c} {3:c}",
  11.                             atmData.Rows[i]["User"],
  12.                             atmData.Rows[i]["PIN"],
  13.                             atmData.Rows[i]["FreeChecking"],
  14.                             atmData.Rows[i]["PersonalSavings"]);
  15.  
  16.                         MessageBox.Show(msg);
  17.                     }
  18.                     catch (Exception)
  19.                     {
  20.                     }
  21.  
  22.                 }
Apr 30 '10 #1
1 1851
tlhintoq
3,525 Expert 2GB
Until someone with more experience can offer more targeted advice I can point you toward these:

Database tutorial Part 1
Database tutorial Part 2
Apr 30 '10 #2

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

Similar topics

3
by: Phil | last post by:
Hi, I have a client/server app. that uses a windows service for the server and asp.net web pages for the client side. My server class has 3 methods that Fill, Add a new record and Update a record....
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
3
by: Angel | last post by:
I have a problem I placed a DropDown list control on my .NET page. I do not want to perform a postback when something is selected. When I want to get what was selected in the Client Script I do not...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
2
by: Nathan Sokalski | last post by:
I have a DropDownList that is returning the value from index 0 regardless of which item is selected. The code that I am using to test which index it is returning is: Label1.Text =...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
7
by: axapta | last post by:
Hi, I have the following however the date is returned in the long format. I want to display as dd/mm/yyyy. If Not drReader.Item("offerstatusdate") Is DBNull.Value Then txtOfferStatusDate.Text =...
2
by: ndeeley | last post by:
Hello, I've written a script which returns the admin rights of users in a table - their access level, and their priviledges. The priviledge are returned to a check box and the admin rights to a...
1
by: Constantine AI | last post by:
Here is the situation i am currently trying to update a sales order using PHP and javascript. When you click on the edit button it brings you a new site page with existing sales order details within....
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: 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...
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:
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.