This is for adding data to the database . Note , it's one of 10s ways to do that .
I'll send you retrieving data in a second .(I'll look for that in another thread)
I'll update this one and post it in a minute .
Last edited by Pirate; Mar 23rd, 2004 at 07:46 PM.
thanks. it works now.
but i tried modifying it and it doesn't work. i can't figure out why.
VB Code:
Public MyPath As String = Application.StartupPath & "\dbDatabase.mdb"
Public MyConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyPath)
that's what i have at form level. and...
[Highlight=VB]
Public Sub SaveDB(ByVal TableStr As String, ByVal _Name As String, ByVal _From As String, ByVal _Until As String)
Dim SQLStr = "SELECT * FROM " & TableStr
Dim MyAdapter As New OleDb.OleDbDataAdapter(SQLStr, MyConnection)
Dim builder As New OleDbCommandBuilder(MyAdapter)
Dim mydataset As New DataSet
MyAdapter.Fill(mydataset, TableStr)
Dim MyDataRow As DataRow = mydataset.Tables(TableStr).NewRow
MyDataRow(0) = _Name
MyDataRow(1) = _From
MyDataRow(2) = _Until
Change the datatypes for From and Until to text . I know they will contain dates and time format but you can always cast that back to its origin type . and Change this line to :
since i've populated a listbox with all the entries in the first column and haven't sorted anything, the order of items in the listbox and the entries in the database should match.
i need to use that information to retreive other information from the same row as the selected entry. i'm not sure if i'm making sense here... but i guess an example should suffice.
my database looks like this:
Code:
nName fFrom uUntil
A 1 2
B 2 3
C 4 5
and my listbox looks like this:
Code:
A
B
C
so what i'm trying to accomplish is to retrieve 1 and 2 when the user chooses A from the listbox, 2 and 3 when s/he chooses B, etc.
whoa.. i just tried something and i think it works
it's the first time i feel like i'm really object-oriented programming
i instantiated 2 new listboxes without creating them using the controls. then i filled up 2nd and 3rd columns into those listboxes. then i made the new listboxes' selected index change to that of the listbox which is on the form. i tested it by MsgBox(lstFrom.SelectedItem) and it gives me the correct entry corresponding to the entry from the "real" listbox.
i think i've just exposed my stupidity here but it's pretty cool. heh.
thanks me