By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,176 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Query Access Database and Display Data on New Form

P: 4
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}
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;")
  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
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.

Sep 6 '10 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 648
#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()
Sep 8 '10 #2

Post your reply

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