473,465 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Query Access Database and Display Data on New Form

4 New Member
I have a program in which I want to have the user enter two percentages and display the data matching the criteria on a new form. The query would be:
Expand|Select|Wrap|Line Numbers
  1. Select *
  2. From Corrosion
  3. Where corrpct1 >= {column in database} OR
  4.       corrpct2 >= {column in database}
  5.  
The way I currently have it written is to display only one row of data. I need to display any number of rows that meet this criteria. My current code is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDetails.Click
  2.         Dim form As New frmDetails()
  3.         Me.Hide()
  4.         form.Show()
  5.         Try
  6.             cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Corrosion.mdb;")
  7.  
  8.             cn.Open()
  9.             cmd = New OleDbCommand("select * from Corrosion", cn)
  10.             dr = cmd.ExecuteReader
  11.             While dr.Read()
  12.                 form.txtID.Text = dr(0)
  13.                 form.txtCountry.Text = dr(1)
  14.                 form.txtCompany.Text = dr(2)
  15.                 form.txtAsset.Text = dr(3)
  16.                 form.txtBlock.Text = dr(4)
  17.                 form.txtFacility.Text = dr(5)
  18.                 form.txtAreaItem.Text = dr(6)
  19.                 form.txtCode.Text = dr(7)
  20.             End While
  21.         Catch
  22.         End Try
  23.         dr.Close()
  24.         cn.Close()
  25.     End Sub
  26.  
This will open the new form and put the information in the textboxes I have. However, I never know how many textboxes I will need to display.

My questions are:

1. How can I do my query to incorporate the user entered criteria (in the where statement)?
2. How can I display ALL of the data instead of just one line?

Thank you for any help you can give.

Rhonda
Sep 6 '10 #1
1 2414
dip_developer
648 Recognized Expert Contributor
#1. your sql query will be like....
Select * From Corrosion Where {column in database} <=corrpct1 OR {column in database}<=corrpct2

#2. If this query returns more than one row then instead of using datareader use dataset....

fill the dataset(say ds) with this sql query

take a datagridview or listview or datalist in the frmDetails form

now put........
Dim form As New frmDetails()
Me.Hide()
form.DataGridview1.DataSource=ds
form.Show()
Sep 8 '10 #2

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

Similar topics

0
by: Doug Beacher | last post by:
I need to import data from a spreadsheet that is created new every day into an MS Access database. The data is in a workbook consisting of multiple work sheets. I plan to import using the...
1
by: programmerKid | last post by:
Hi, I am trying to open mdb file to view tables in it but when I open mdb file it run form in it by itself, as a startup point. Can anyone please tell me how to view and change in tables and...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
5
by: Bec | last post by:
I'm in desperate need of your help.. I need to build an access database and have NO idea how to do this.. Not even where to start.. It IS for school, and am not asking anyone to do my...
11
by: saurabhbpl | last post by:
hi, i have a html drop down menus and i want to conver it into dynamically means that menu show data from database.how can i fetch data from database for using menus and sub menus using php and...
2
by: amitp | last post by:
I've an order placing application which generates reports(RTF) for a particular order deatils. My Vb applicaiton retrieves all the details for the particular order from the database and puts it in an...
0
by: asad56 | last post by:
I am workin with a superstore managment project. I connect Access database with main form . Then it work properly. But now I connect same database with another table or field in another form which is...
1
by: evilash | last post by:
Hi, am creating a web form in visual studio to insert data into an access database. The web form text boxes on the aspx file are Textbox.Text, Textbox2.Text and Textbox4.Text. The info is going to...
6
by: mandanarchi | last post by:
Before I begin I want to apologise if my explanations are less than clear; that said, I'll try and be as detailed as possible. Scenario: User (XP OS, running office 2003) - IP = 1xx.x.x.101...
14
by: SunnyC | last post by:
I have a table as below in test.mdb Access database. on a form, I want to use lookup to capture the the last field name in a text on the form, in this case, it is 200906. by using some code I...
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:
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,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.