addicktz
asked on
Simple Databse Question.
Hi, I dont want to bind my data to anything, except maybe an array which im not sure how to do, my question here is, that I would like to know the proper way in dealing wtih databases, as of right now I have two tables, I will constantly need to be searching thru each one of them for things in different fields, and I will constantly be adding to one of the tables, at a very fast rate for the most part. My question is how would I go about doing this correctly?
Would I open one connection for the db?
What would be the fastest way to search for something in say table: tblnick field: lastseen searching for: "Two" and return that row id?
Will I be updating after every entry? or is that only when i save? I will need uptodate results.
thank you =)
Would I open one connection for the db?
What would be the fastest way to search for something in say table: tblnick field: lastseen searching for: "Two" and return that row id?
Will I be updating after every entry? or is that only when i save? I will need uptodate results.
thank you =)
ASKER
I appreciate the link but wasnt what I was looking for, But here's something else to add to this question,
would it be possible to bind a table to a structure?
public structure bot
dim address as string
dim nick as string
end structure
dim bots() as bot
redim bots(db.rows.count) as bot
and then bind the two fields in the database to bots().address and bots().nick with maybe a loop?
would it be possible to bind a table to a structure?
public structure bot
dim address as string
dim nick as string
end structure
dim bots() as bot
redim bots(db.rows.count) as bot
and then bind the two fields in the database to bots().address and bots().nick with maybe a loop?
ASKER
and have new instances of bots() be recorded to the db ?
i am not sure whether you can bind to a structure, but definitely you can bind to a class, by just inheriting it from control. Take a look at the followin example --
PUblic class bot
inherits control
dim address as string
dim nick as string
end class
dim bots() as bot
redim bots(db.rows.count) as bot
bots(0).databindings.add(" address",d ataset,"ta blename")
PUblic class bot
inherits control
dim address as string
dim nick as string
end class
dim bots() as bot
redim bots(db.rows.count) as bot
bots(0).databindings.add("
Well in your case i think the best way is to have a Dataset with two tables.
The dataset will be disconnected so yuo need just one connection say on Form Load and fill the Tables in the DataBase.
As for the tables where you'll have heavy DataEntry, You can have the Entries in disconnected mode (Unless of course where you have an AutoGenerate Primary Key and more than one Users, in such a case you'll need some concurrency measures)
After all the entries are done database connection can be opened and all data stored back.
Now for the table from where you need to search often, You can use DataViews to filter the records in the second table giving where clause like "lastseen = 'Two'"
The dataset will be disconnected so yuo need just one connection say on Form Load and fill the Tables in the DataBase.
As for the tables where you'll have heavy DataEntry, You can have the Entries in disconnected mode (Unless of course where you have an AutoGenerate Primary Key and more than one Users, in such a case you'll need some concurrency measures)
After all the entries are done database connection can be opened and all data stored back.
Now for the table from where you need to search often, You can use DataViews to filter the records in the second table giving where clause like "lastseen = 'Two'"
I prefer to use dataView objects, in different comboBox objects you can select the search criteria from them and then update the rowFilter property of your dataView, when I want to filter very fast, i do this.
Well, I fill the comboBox objects manually, because if I do this in that way, I can add an 'All' item to indicate that that criteria will be discarded.
ASKER
eozz: can you say all that again in a tad more detail, and maybe show some sample code?
you guys have been very helpful, thank you all.
you guys have been very helpful, thank you all.
Ups, well, the code could be so large... but with this explanation I think you'll understand:
-Suppose that you have this table Products(Name, Size, Cost, Color)
-You must create 4 comboBox
The code of the first comboBox is this:
dim com as new OleDbCommand("SELECT DISTINCT Name FROM Products",Connection)
dim dr as OleDbDataReader = com.ExecuteReader()
while dr.Read
me.cbName.Items.Add(dr.Ite m("Name"))
wend
me.cbName.Items.Add "All"
You must analog things to fill the other comboBox
-In the selectedIndexChanged of your comboBox objects you must do something like this:
me.ApplyFilters()
private sub ApplyFilters()
dim bolFirst as Boolean = True
myDataView.rowFilter = ""
if cbName.Text <> "All" then
bolFirst = False
myDataView.RowFilter = "Name = '" & cbName.Text & "'"
end if
if cbSize.Text <> "All" then
if not bolFirst then myDataView.RowFilter &= ", "
myDataView.RowFilter &= "Size = '" & cbSize.Text & "'"
end if
if cbCost.Text <> "All" then
if not bolFirst then myDataView.RowFilter &= ", "
myDataView.RowFilter &= "Cost = '" & cbCost.Text & "'"
end if
if cbColor.Text <> "All" then
if not bolFirst then myDataView.RowFilter &= ", "
myDataView.RowFilter &= "Color = '" & cbColor.Text & "'"
end if
end sub
-Suppose that you have this table Products(Name, Size, Cost, Color)
-You must create 4 comboBox
The code of the first comboBox is this:
dim com as new OleDbCommand("SELECT DISTINCT Name FROM Products",Connection)
dim dr as OleDbDataReader = com.ExecuteReader()
while dr.Read
me.cbName.Items.Add(dr.Ite
wend
me.cbName.Items.Add "All"
You must analog things to fill the other comboBox
-In the selectedIndexChanged of your comboBox objects you must do something like this:
me.ApplyFilters()
private sub ApplyFilters()
dim bolFirst as Boolean = True
myDataView.rowFilter = ""
if cbName.Text <> "All" then
bolFirst = False
myDataView.RowFilter = "Name = '" & cbName.Text & "'"
end if
if cbSize.Text <> "All" then
if not bolFirst then myDataView.RowFilter &= ", "
myDataView.RowFilter &= "Size = '" & cbSize.Text & "'"
end if
if cbCost.Text <> "All" then
if not bolFirst then myDataView.RowFilter &= ", "
myDataView.RowFilter &= "Cost = '" & cbCost.Text & "'"
end if
if cbColor.Text <> "All" then
if not bolFirst then myDataView.RowFilter &= ", "
myDataView.RowFilter &= "Color = '" & cbColor.Text & "'"
end if
end sub
ASKER
I am actually trying to avoid putting any information in objects like listbox/combobox, I would prefer to do it in all arrays, but, my question now is, is arrays amounting to over 15000 to much?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/adoplusoverview.aspx
If you look on the left pane you'll have topics like " Update a Database from a DataSet" which is one of your queries. Plus there are plenty more useful links. Hope that helps.