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

How do I use Combo Box and Text Fields to selectively sort a database?

I have posted a couple times on here already and found the user community to
be very helpful. I took on a project before I realized how difficult a time
I'm having working with a database. Assistance would be greatly appreciated!

I am trying to allow certain users to be able to preview a database's
contents without being able to update which I've accomplished. I've created a
"Preview" button and set the datagrid to READ ONLY. Now I want to be able to
enable certain users to create new entries in the database. I have a Combo
Box field with items representing data ranges (ex. 100xxx, 200xxx, 300xxx etc.
) representing AutoCAD drawing numbers. I'd like to be able to selectively
sort the database based on a range if they choose one in the Combo Box. I
also have a Text field which the user can enter a specified drawing number
(ex. 123456) and have the app search the database and display only that entry.
I'm using a datagrid to display the results. I can pull up the entire
database, but cannot figure out how to sort based on entries in the combo box
or text fields.

In addition I used the Data Form Wizard to create individual field text boxes
and the Navigate (<<, <, >, >>) buttons for the same database on the same
form at the bottom. I'd like it if the user could use either the datagrid or
the individual fields to perform data entry. Unfortunately I can't seem to
link the fields with the database entries. I can specify a row and write that
to the text boxes but that's by hard coding it. I'd like to be able to just
navigate through the database using the Navigate buttons.

Public Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.
EventArgs) Handles btnLoad.Click
Dim dataset1 As New DataSet1
'Dim dataset2 As New DataSet
'dataset2 = New DataSet("dataset2")
Dim ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source = C:\AutoCAD Project\AutoCAD Files.mdb; User ID=Admin"
Dim Connection1 As OleDbConnection = New OleDbConnection
(ConnectionString)
Dim Command1 As OleDbCommand = New OleDbCommand("SELECT * FROM
[AutoCAD Files]", Connection1)

Connection1.Open()
Command1.Connection = Connection1

Dim daAdapter1 As OleDbDataAdapter = New OleDbDataAdapter
Dim daAdapter2 As OleDbDataAdapter = New OleDbDataAdapter

daAdapter1.SelectCommand = Command1
DataGrid1.Visible = True
daAdapter1.Fill(dataset1, "AutoCAD Files")
DataGrid1.SetDataBinding(dataset1, "AutoCAD Files")

' Check if a drawing number range is selected
'If ComboBox1.SelectedItem <> "" Then
'Dim Command2 As OleDbCommand = New OleDbCommand("SELECT * FROM
[AutoCAD Files] where [File Name] LIKE [combobox1.selecteditem]", Connection1)

'End If

' Check if a drawing number is specified
If TextBox3.Text <> "" Then
'Dim command2 As OleDbCommand = New OleDbCommand("select * from
[AutoCAD Files] where [FILE NAME] like " & Trim(TextBox3.Text) & "",
Connection1)
daAdapter2.SelectCommand = command2
daAdapter2.Fill(dataset1, "AutoCAD Files")
DataGrid1.SetDataBinding(dataset1, "AutoCAD Files")
End If

'editID.Text = dataset1.Tables("AutoCAD Files").Rows(0).Item(0)
'editFILE_NAME.Text = dataset1.Tables("AutoCAD Files").Rows(0).Item(1)

'editFILE_TITLE.Text = dataset1.Tables("AutoCAD Files").Rows(0).Item
(2)
'editFILE_DESCRIPTION.Text = dataset1.Tables("AutoCAD Files").Rows(0).
Item(3)
'editREV_LETTER.Text = dataset1.Tables("AutoCAD Files").Rows(0).Item
(4)
'editORIGINATION_DATE.Text = dataset1.Tables("AutoCAD Files").Rows(0).
Item(5)
'editDATE_MODIFIED.Text = dataset1.Tables("AutoCAD Files").Rows(0).
Item(7)
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancel.Click
Me.BindingContext(objDataSet1, "AutoCAD Files").CancelCurrentEdit()
Me.objDataSet1_PositionChanged()
ActiveForm.Hide()
End Sub
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200509/1
Nov 21 '05 #1
3 4238
Hi,

If I see it well, than you can for your second part of your problem use
databinding.

Have a look at this sample on our website,

http://www.windowsformsdatagridhelp....9-4deb7fa4a0b8

Don't forget to do before you update with a button an endcurrentedit.

BindingContext(ds.Tables(0)).EndCurrentEdit()

Data is pushed into the datarow after a rowchange or with this command.

I hope this helps,

Cor
Nov 21 '05 #2
I am trying to implement what I see on your website. I'm including the code
from your site that I based my first try at coding on (see below). The first
field in my table is called "ID" and is an auto number. I'm trying to
populate the textbox field called editID that was created from the Data Form
Wizard with the "ID" field out of my table named "AutoCAD Files".

Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField")
TextBox1.DataBindings.Add(Mybinding)

Dim IDbinding As New Binding("Text", dataset1.Tables(0), "AutoCAD Files.ID")
editID.DataBindings.Add(IDbinding)

I'm getting the following error message on the line "editID.DataBindings.Add
(IDbind)"

An unhandled exception of type 'System.ArgumentException' occurred in system.
windows.forms.dll

Additional information: This would cause two bindings in the collection to
bind to the same property.

BTW...is there a URL somewhere that more simply explains how VB.NET handles
databases? I'm using "SAMS Teach Yourself VB.NET 2003" as my reference. It's
kind of difficult to grasp this concept.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200509/1
Nov 21 '05 #3
>I am trying to implement what I see on your website.

Why are you not just trying.

If you right click on the text. tell copy and than paste that in a form and
put that textbox and twee buttons on it, you see exactly what happens.

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Marnie Parker | last post by:
I am adding a drop down comb box to an existing database I wrote about a year ago. This combo box list names where the user can select which record to go to. Sigh. Last, First Name and a...
4
by: RBohannon | last post by:
I'm using Access 2000. I currently have a report being generated using the results of a query by form. The form used for this query is an unbound form, frmListDialog. frmListDialog contains...
1
by: Gary | last post by:
I am working on this database that has a table ( tbl_main ) with the following 3 fields (amongst many fields in the table): Product, PanelType and Thickness Product (text field - combo box...
4
by: LD | last post by:
Is there a way in Access to store more than one value in a field that has been selected from a combo box? For example, if a combo box had three values that you can select, "One", "Two", and...
8
by: AFN | last post by:
I want to have a routine in a page base class that will take all the text fields on a web form, and then HtmlEncode their values. I'm having trouble figuring out if I want to loop controls or...
1
by: Bill | last post by:
Problem: Combo box data disappears from view when a requery is done See "Background" below for details on tables, forms & controls On a form, I want to use the setting of bound combo box C1...
4
by: Dave | last post by:
I wasn't sure how to search for previous posts about this, it felt real specific. Ok so here's the database & problem: I have 4 combo boxes: cboServer, cboPolicy, cboDB, and cboApplication. ...
2
by: biganthony via AccessMonster.com | last post by:
Hi, I decided to install Office 2003 Service Pack 3 on my home computer to test (in full knowledge that there may be some issues with it). After installation, I have noticed that with a small...
4
klarae99
by: klarae99 | last post by:
Hello, I am working on an Access 2003 Database. The tables that pertain to this issue are tblOrg, tblState, tblCity, and tblZip. I have posted the table structure with only the pertinant fields...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: 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:
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
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.