Getting right record to fill dt

ckeezer

Well-known member
Joined
Jan 16, 2006
Messages
100
Programming Experience
1-3
The idea here is that I have a seach form that contains a txt field, a btn and a dg. When the user starts to type in the txt field the dg filters the data. The user has to highlight a row for editing, then click on the btn. What is supposed to happen is that record is supposed to display on another form, customers1, and allow for changes.

right now, I can get everything to work, but when you click on the btn, it pulls the first record in the dt not the current row. I think I am just missing it here.

By the Way, THANKS VIS781 for all the help thus far.

here is the code for the form:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Search_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] conn [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\SmartHouse1.mdb")
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] adapter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbDataAdapter("SELECT CustomerID, CompanyName, FirstName, LastName, PhoneNumber FROM Customers", conn)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dt [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataTable("Customers")
adapter.Fill(dt)
dgCompanys.DataSource = dt
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] txtCompanyName_TextChanged([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] txtCompanyName.TextChanged
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dvFilter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataView = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]TypeOf[/COLOR][/SIZE][SIZE=2] dgCompanys.DataSource [/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] DataView [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dvFilter = [/SIZE][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][SIZE=2](dgCompanys.DataSource, DataView)
[/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]TypeOf[/COLOR][/SIZE][SIZE=2] dgCompanys.DataSource [/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] DataTable [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dvFilter = [/SIZE][SIZE=2][COLOR=#0000ff]CType[/COLOR][/SIZE][SIZE=2](dgCompanys.DataSource, DataTable).DefaultView
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] txtCompanyName.TextLength > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]dvFilter.RowFilter = "CompanyName LIKE '" & txtCompanyName.Text & "*'"
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]dvFilter.RowFilter = ""
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]dgCompanys.DataSource = dvFilter
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnEdit_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnEdit.Click
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] dgCompanys.CurrentRowIndex > -1 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] form [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Customers1
[/SIZE][SIZE=2][COLOR=#008000]'form.txtCustomerID = CType(dgCompanys.Item(dgCompanys.CurrentRowIndex, 0), Char)
[/COLOR][/SIZE][SIZE=2]form.Show()
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]MessageBox.Show("Please select a row for editing.", "No Row Selected")
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
 
VIS,
I think it is the update query that I am not understanding. Do I need to use the dataadapters.update method or do I actually need to use a sql statement that says

VB.NET:
"UPDATE Customers SET CompanyName= &txtCompanyName.Text&...WHERE CustomerID =?"
Then give it the parameters for CustomerID

Once I write the statement how do I update the dataadapter... the right way?
 
here is what I have, but I am getting an error that dataadapter cannot contain that many arguments:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] mnuUpdate_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] mnuUpdate.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strSQL [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"UPDATE Customers SET CompanyName = '"[/COLOR][/SIZE][SIZE=2] & txtCompanyName.Text & [/SIZE][SIZE=2][COLOR=#800000]"',"[/COLOR][/SIZE][SIZE=2] _
& [/SIZE][SIZE=2][COLOR=#800000]"FirstName='"[/COLOR][/SIZE][SIZE=2] & txtFirstName.Text & [/SIZE][SIZE=2][COLOR=#800000]"',LastName='"[/COLOR][/SIZE][SIZE=2] & txtLastName.Text & [/SIZE][SIZE=2][COLOR=#800000]"',"[/COLOR][/SIZE][SIZE=2] _
& [/SIZE][SIZE=2][COLOR=#800000]"Address='"[/COLOR][/SIZE][SIZE=2] & txtAddress.Text & [/SIZE][SIZE=2][COLOR=#800000]"',City='"[/COLOR][/SIZE][SIZE=2] & txtCity.Text & [/SIZE][SIZE=2][COLOR=#800000]"',State='"[/COLOR][/SIZE][SIZE=2] & txtState.Text & [/SIZE][SIZE=2][COLOR=#800000]"',"[/COLOR][/SIZE][SIZE=2] _
& [/SIZE][SIZE=2][COLOR=#800000]"Zip='"[/COLOR][/SIZE][SIZE=2] & txtZip.Text & [/SIZE][SIZE=2][COLOR=#800000]"',PhoneNumber='"[/COLOR][/SIZE][SIZE=2] & txtPhoneNumber.Text & [/SIZE][SIZE=2][COLOR=#800000]"',FaxNumber='"[/COLOR][/SIZE][SIZE=2] & txtFaxNumber.Text & [/SIZE][SIZE=2][COLOR=#800000]"',"[/COLOR][/SIZE][SIZE=2] _
& [/SIZE][SIZE=2][COLOR=#800000]"EmailAddress='"[/COLOR][/SIZE][SIZE=2] & txtEmailAddress.Text & [/SIZE][SIZE=2][COLOR=#800000]"' WHERE CustomerID = ? "
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OleDbConnection1.Open()
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OleDbDataAdapter1.Update(strSQL)
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] fillException [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Exception
[/SIZE][SIZE=2][COLOR=#0000ff]Throw[/COLOR][/SIZE][SIZE=2] fillException
[/SIZE][SIZE=2][COLOR=#0000ff]Finally
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].OleDbConnection1.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
 
Ckeezer, what happend to those parameters? We spend ages on them a while back and i thought you had it down, now you've suddenly gone back your string concatenation.. why?
 
I thought that would only work with a select statement?!
Understanding how to use it in a select statement, how do you do the same thing for an update statement:
VB.NET:
Dim da as New OleDbDataAdapter
Dim strSQL as String = "UPDATE Customers SET CompanyName=?, FirstName=?...etc"
dim cmd as new oledbcommand(strSQL, conn)
cmd.parameters.add(....)
da.update(cmd)
 
Last edited by a moderator:
exactly as you have done it..


VB.NET:
UPDATE Customers SET CompanyName = ? , FirstName = ? etc....


Add the parameters for each question mark in the query, and you are done. If you have any problems post back.

NB You can use parameters for any type of query UPDATE, DELETE, INSERT, SELECT
 
I am getting the following error:
Error 1 Overload resolution failed because no accessible 'Update' can be called with these arguments:
'Public Function Update(dataTable As System.Data.DataTable) As Integer': Value of type 'System.Data.OleDb.OleDbCommand' cannot be converted to 'System.Data.DataTable'.
'Public Function Update(dataRows() As System.Data.DataRow) As Integer': Value of type 'System.Data.OleDb.OleDbCommand' cannot be converted to '1-dimensional array of System.Data.DataRow'.
'Public Overrides Function Update(dataSet As System.Data.DataSet) As Integer': Value of type 'System.Data.OleDb.OleDbCommand' cannot be converted to 'System.Data.DataSet'. D:\Documents and Settings\ckeezer\Desktop\Smart House, INC\Smart House, INC\Customers1.vb 652 9 SmartHouse


Here is the code:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] conn [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbConnection([/SIZE][SIZE=2][COLOR=#800000]"Provider=Microsoft.Jet.OleDb.4.0;Data Source = "[/COLOR][/SIZE][SIZE=2] & Application.StartupPath & [/SIZE][SIZE=2][COLOR=#800000]"\SmartHouse1.mdb"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strSQL [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"UPDATE Customers SET CompanyName = ?, FirstName = ?, LastName = ?,"[/COLOR][/SIZE][SIZE=2] _
& [/SIZE][SIZE=2][COLOR=#800000]"Address = ?, City= ?, State= ?, Zip= ?, PhoneNumber= ?, FaxNumber= ?,"[/COLOR][/SIZE][SIZE=2] _
& [/SIZE][SIZE=2][COLOR=#800000]"EmailAddress= ? WHERE CustomerID = ?"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cmd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbCommand(strSQL, conn)
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@CompanyName"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"CompanyName"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtCompanyName.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@FirstName"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"FirstName"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtFirstName.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@LastName"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"LastName"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtLastName.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@Address"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"Address"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtAddress.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@City"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"City"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtCity.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@State"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"State"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtState.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@Zip"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"Zip"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtZip.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@PhoneNumber"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"PhoneNumber"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtPhoneNumber.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@FaxNumber"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"FaxNumber"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtFaxNumber.Text
cmd.Parameters.Add([/SIZE][SIZE=2][COLOR=#800000]"@EmailAddress"[/COLOR][/SIZE][SIZE=2], OleDbType.VarWChar, 255, [/SIZE][SIZE=2][COLOR=#800000]"EmailAddress"[/COLOR][/SIZE][SIZE=2]).Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtEmailAddress.Text
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] da [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbDataAdapter
da.Update(cmd)
[/SIZE]
 
Nearly, you just missed out a step...

VB.NET:
Da.UpdateCommand = Cmd
 
Da.Update(your datatable)


Still, i think you should be using the same dataadapter as the one you filled the datatable with.
 
Oooh, it appears like we are all making this rather too much like hard work. ckeezer, I've downloaded the project you posted; there is no settings file (so it's broken a little) but what I am going to do is take the database out of it, and a couple of the forms and make a new project as a start for how this kind of thing is actually done in .net 2. wait a short time for me to prepare the project. After preparation if you have questions about how it was achieved, I'll happily make a screenrecording for you
 
OK, it took me about 15 minutes to generate this to the following:

New project
Add datasource
Choose access file db
Tick all tables
Modify generated adapters to take all that junk off the end of the update statements for Custoemrs and Orders
Ensure primary keys are set for Cust/Ord
Alter relation to cascade updates and deletes from Cust to Ord
Add query to each TA; customers gets query SELECT * FROM Customers WHERE LastName = ?; orders gets query SELECT * FROM Orders where customerID = ? (customerID is an FK of Customers.CustomerID. it is prudent to add a query selecting all records from a table based on the columns that table has in relaition to another table PK/FK setup)
Add New form
Open form, open Data Sources window
Set Customers datasource to details mode and drag it onto form.
Textboxes, ds and binding nav appears
Renamed DataSet to ..DSInstance because the namer names it identical to its type, by default and that is bad/confusing
Customers datasource has a child node of Orders, dragged to form
New bindingsources appear, bound to relation between tables
Added Find button next to last name as crude implement of your search screen
Added code in form load to load all customer and order records
Added code for Save button to perform database updates
Added code for find button to clear DS, find all custoemrs with given lastname (uses new query) then for each found customer retrieve their orders (uses new query)
 

Attachments

  • SmarterHouse.zip
    167.2 KB · Views: 39
Comments on the project file you posted:


strive for consistency of naming. you have forms called:
frmAllResCustomers
Main
password
Customers1

you appear to make a new dataset for each datatable. this will make things much harder to design and maintain.

you apepar to have multiple datatables and im not sure why. the DT in dsEmployee and dsEmployees1 appear similar but only one is found in the database. the dsCustomers and dsCustomers1 are identical?

avoid prefixing everything with obj - given that everything in an OO language is descended from Object (apart from primitives like int, boolean), the obj notion is a little moot
 
While I understand what you have done... I need to have the ability to search for a record. The way you have it setup in the example, it is simply pulling every record from the db.
I need to have a search form, like the one in my project, that will allow for the user to search based on the Company name, then have that record pulled into the customers form, have the user update information, save it back to the db and be able to do it all over again.

Also, your save btn is not functioning... When I click on save after making changes to the recordset, close the app then reopen, nothing changes... any ideas why?
 
Also... this is not a production project... I have created and deleted several dataset, adapters and other items. I am not worried right now about the naming conventions, as much as how I accomplish the task. Once I get that down. I will recreate the project with the proper namings. But thanks for the insight.
 
While I understand what you have done... I need to have the ability to search for a record. The way you have it setup in the example, it is simply pulling every record from the db.

Indeed.. that's a quick default to let you get to play with the stuff, It is done in the form load, 2 lines of code and these lines of code should be deleted..

I need to have a search form, like the one in my project, that will allow for the user to search based on the Company name,
Your existing search form showed LastName, so i quickly mimicked that using the Find button. We will get to this particular running later; let's walk first (plus, bear in mind I was doing this on a time constraint :) )

Review the code of the Find button. you could turn this into a public method of frmCustomer, called ShowCustomersByName. Later i will show you how i implemented my company's request to "search on any field of any form in any table"

then have that record pulled into the customers form, have the user update information, save it back to the db and be able to do it all over again.
review the Find button:
type asdf into the lastname and click Find, no records are shown
type Hicklory and Find. Only hickroy record is shown :)

Also, your save btn is not functioning... When I click on save after making changes to the recordset, close the app then reopen, nothing changes... any ideas why?
oh, it's functioning; i tested it.
I actually feel the problem lies elsewhere: this project uses a file based database. File based databases live in the same directory as the source code and are copied to the bin\Debug or bin\Release when the project is started. A variable controls this behaviour:
Copy always
Copy if newr
Do not copy

By default it is copy always, so the source DB will always overwrite any DB your program updates. This can make it look like the db isnt updating, it is but the changes are being replaced by an older database.

I set the copy to Copy If Newer. File time is compared for this. I live in england, it may be that you live in america or somewhere behind me in time so my database that I last modified (the source) will be newer than anything you modify for a good number of hours. Try changing the copy mode to Do Not Copy, of the SmartHouse1.mdb
 
PS; there ARE 8 different ways to get to the finish line. its very frustrating, this ado.net stuff! :)
 
Back
Top