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

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
>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 discussion thread is closed

Replies have been disabled for this discussion.