Updating Database from class. Trying to think of a way to iterate or "go through"
my program has several sections where a total of 32 labels have to call table acctsnm from the database. I dont really want to have to connect every form to the databse when i am just doing the same call. is there any way to call the items i need from the table colomn in a clas that i can call everytime i need this procedure to be run.
Thanks
Hi,
Yes you can create a Public Sub method in a class or
why don't you just create a new Sub or function to do this?
Would you need an example?
Can you write a pseudo-line of code that might demonstrate
what you are trying to do please?
Dim myItem As String
Dim mySelectString As String
' A pseudo line of code where myDB is the CLASS.>>
myItem=myDB.Select(mySelectString)
Regards,
S_DS
An example would be great! I am a bit of a novice and while i have developed other programs with vb.net this is my first db driven one. here is some pseudo code to kinda say what im trying to do
'acct1lbl looks in side of the keoflex dataset.xml which is connected to the keoflex.mdb.
'it looks at table "Accounts"
'then it looks at colomn Acctnm under field 1
in otherwords i want label 1 to say what ever is in the Accounts - acctnm - field 1
I have two forms in this program that will call the same procedure
I have 32 labels.
label 1 = accounts - acctnm - field 1
label 2 = accounts -acctnm -field 2
label 3 = accounts - acctnm - field 3
you get the point.
Was this enough info
The next part of the script i have allready written but it essentially looks to see if the label is "New Account" if so the label and text box are visible = false. and the visible texboxes and labels move in line. the code for that is below for the first 3 tables and labels.
Public
Class DepositDim result As DoubleDim counter As Double = 0Dim boxmover, lblmover As ObjectPrivate Sub arrangelbls()If counter = 1 Thenboxmover.location =
New Point(12, 212)lblmover.location =
New Point(12, 234)ElseIf counter = 2 Thenboxmover.location =
New Point(12, 252)lblmover.location =
New Point(12, 274)ElseIf counter = 3 Thenboxmover.location =
New Point(12, 292)lblmover.location =
New Point(12, 314)End IfEnd SubPrivate Sub Deposit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Acct1Lbl.Text = "New Account" ThenAcct1Lbl.Visible =
FalseAcct1txt.Visible =
FalseElsecounter = counter + 1
boxmover = Acct1txt
lblmover = Acct1Lbl
Call arrangelbls()End IfIf acct2lbl.Text = "New Account" Thenacct2lbl.Visible =
Falseacct2txt.Visible =
FalseElsecounter = counter + 1
boxmover = acct2txt
lblmover = acct2lbl
Call arrangelbls()End IfIf acct3lbl.Text = "New Account" Thenacct3lbl.Visible =
Falseacct3txt.Visible =
FalseElsecounter = counter + 1
boxmover = acct3txt
lblmover = acct3lbl
Call arrangelbls()End IfEnd Sub
End
Class Thanks
Michael
Hi,
By putting all the labels in an array you can then refer to them within a LOOP. 
Regards,
S_DS
P.S. With regards the database side of it all please refer to some of these url links.>>
Access database.>>
Sql database.>>
Database.>>
Sorry i can't give a full example myself.
--
Dim
lblArray(32) As ObjectDim index As IntegerDim acc1 As New Account("Fred Bloggs", 203040, 12345678)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Make the label Label1 tall enough to see 3 lines of text.
Label1.Height = 50
lblArray(1).Text = acc1.Name & vbCrLf & acc1.SortCode & vbCrLf & acc1.AccountNumber
End Sub
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadlblArray(1) = Label1
lblArray(2) = Label2
lblArray(3) = Label3
lblArray(4) = Label4
lblArray(5) = Label5
lblArray(6) = Label6
lblArray(7) = Label7
lblArray(8) = Label8
lblArray(9) = Label9
lblArray(10) = Label10
lblArray(11) = Label11
lblArray(12) = Label12
lblArray(13) = Label13
lblArray(14) = Label14
lblArray(15) = Label15
lblArray(16) = Label16
lblArray(17) = Label17
lblArray(18) = Label18
lblArray(19) = Label19
lblArray(20) = Label20
lblArray(21) = Label21
lblArray(22) = Label22
lblArray(23) = Label23
lblArray(24) = Label24
lblArray(25) = Label25
lblArray(26) = Label26
lblArray(27) = Label27
lblArray(28) = Label28
lblArray(29) = Label29
lblArray(30) = Label30
lblArray(31) = Label31
lblArray(32) = Label32
End Sub
Hi,
Re: Updating Database from class.
I'm trying to think of a way to iterate or "go through" the field numbers.
Maybe someone else on here can answer this?
You may have to set up another array to do this.
I've seen a method of how to add a number onto the end of a control name
using string operations i think, but i can't remember where i saw it.
It may be on here or somewhere on http://www.programmersheaven.com
So that Label, Label2 etc
Field1,Field2 etc can be referred to in code.
Regards,
S_DS