|
-
Mar 2nd, 2004, 05:39 PM
#1
Thread Starter
Addicted Member
Find a record in ADO .NET
Might be very simple to everyone. But I need it soon. No time to research.
VB Code:
Dim ADOConOle As OleDb.OleDbConnection
ADOConOle = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Application.StartupPath & "\Accounts.mdb")
Dim rsLocal As New OleDb.OleDbDataAdapter
Dim rsCurrent As New DataSet
rsLocal.SelectCommand = New OleDb.OleDbCommand("SELECT * FROM CUSTOMER", ADOConOle)
txtCustID.DataBindings.Add("text", rsCurrent.Tables(0), "Cust_Id")
txtName.DataBindings.Add("text", rsCurrent.Tables(0), "Name")
txtAddress1.DataBindings.Add("text", rsCurrent.Tables(0), "Address1")
txtAddress2.DataBindings.Add("text", rsCurrent.Tables(0), "Address2")
txtAddress3.DataBindings.Add("text", rsCurrent.Tables(0), "Address3")
I just want to do display a record (like Find method in ADO) for the entered ID in txtCustID field.
Thanks
Susindran
-
Mar 3rd, 2004, 10:15 AM
#2
Lively Member
Hello,
you need to use a dataview so you can sort/filter a dataset.
Look :
VB Code:
Dim dv as dataview = ds.tables(0).defaultview
dv.RowFilter = "City = 'Berlin'"
HTH !
-
Mar 3rd, 2004, 11:36 AM
#3
Thread Starter
Addicted Member
Does it Filter (like in ADO) or Find?
Thanks
Susindran
-
Mar 3rd, 2004, 05:08 PM
#4
Lively Member
It filters. But I don't see the difference between 'find' and 'filter'.
-
Mar 5th, 2004, 08:38 AM
#5
Thread Starter
Addicted Member
How do I bind to the text fields again with the found record?
Thanks
-
Mar 9th, 2004, 09:34 AM
#6
Thread Starter
Addicted Member
-
Mar 9th, 2004, 10:00 AM
#7
Addicted Member
Are you trying to search you dataset for a row say with the ID "10" then return the column values for that row?
Is the column ID your primary key in your database?
Last edited by Hole-In-One; Mar 9th, 2004 at 10:04 AM.
-
Mar 10th, 2004, 08:23 AM
#8
Thread Starter
Addicted Member
You are exactly correct.
Cust_Id is the Primary Key in table CUSTOMER.
I am able to bind and navigate it. But unable to find a record (also not able to save it).
I couldn't find any help in any site or book regarding finding a record and binding it back to controls.
Thanks
-
Mar 11th, 2004, 09:01 AM
#9
Member
It has to be possible as the typed Datasets has a built in function for each table where you can find a row by using the primary key. So for example if a table has a primary key named CustomerID a typed dataset will have a function for that table named FindByCustomerID.
Create a typed dataset using the drag and drop in a project and search for that function to see how its done if you don't want to go with a typed dataset yourself.
/Nisse
-
Mar 11th, 2004, 11:01 AM
#10
Thread Starter
Addicted Member
I am new to .Net. Can you post with sample code?
Thanks
-
Mar 12th, 2004, 09:31 AM
#11
Member
Create a typed dataset using the drag and drop in a project and search for that function to see how its done if you don't want to go with a typed dataset yourself.
Create a table in for example SQL and give it a primary key. Drag the table from the server explorer (next to the toolbox) in VS and drop it on a form. A connection to the database and a dataadapter will be created. Rightclick the dataadapter and choose "generate dataset". You know have yourself a typed dataset. Enter the code and look for the FindByXXXX function where XXXX is the name of your primary key column.
/Nisse
-
Mar 12th, 2004, 11:53 AM
#12
PowerPoster
Hi unisse,
"Create a table in for example SQL and give it a primary key. Drag the table from the server explorer (next to the toolbox) in VS and drop it on a form."
I'm completely lost on this. Where exactly is the "Server Explorer"? I have nothing next to the toolbox.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 15th, 2004, 02:25 AM
#13
Member
If its not visible next to the toolbox, it can be found here:
View -> Server Explorer.
-
Mar 15th, 2004, 03:49 AM
#14
PowerPoster
Hi unisse,
Many thanks. I shall enjoy looking at that!!
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 15th, 2004, 09:19 AM
#15
PowerPoster
"Create a table in for example SQL and give it a primary key. Drag the table from the server explorer (next to the toolbox) in VS and drop it on a form."
Don't forget to rightclick on the DataConnection node in the Server Explorer to create a reference to your database.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|