Updating Database from class

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

[358 byte] By [xion.truth] at [2007-12-28]
# 1

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

Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

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 Deposit

Dim result As Double

Dim counter As Double = 0

Dim boxmover, lblmover As Object

Private Sub arrangelbls()

If counter = 1 Then

boxmover.location = New Point(12, 212)

lblmover.location = New Point(12, 234)

ElseIf counter = 2 Then

boxmover.location = New Point(12, 252)

lblmover.location = New Point(12, 274)

ElseIf counter = 3 Then

boxmover.location = New Point(12, 292)

lblmover.location = New Point(12, 314)

End If

End Sub

Private Sub Deposit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Acct1Lbl.Text = "New Account" Then

Acct1Lbl.Visible = False

Acct1txt.Visible = False

Else

counter = counter + 1

boxmover = Acct1txt

lblmover = Acct1Lbl

Call arrangelbls()

End If

If acct2lbl.Text = "New Account" Then

acct2lbl.Visible = False

acct2txt.Visible = False

Else

counter = counter + 1

boxmover = acct2txt

lblmover = acct2lbl

Call arrangelbls()

End If

If acct3lbl.Text = "New Account" Then

acct3lbl.Visible = False

acct3txt.Visible = False

Else

counter = counter + 1

boxmover = acct3txt

lblmover = acct3lbl

Call arrangelbls()

End If

End Sub

End Class

Thanks

Michael

xion.truth at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Hi,

Go to PROJECT MENU then ADD CLASS and name the CLASS as Account.Vb

Delete all the text and then PASTE this lot in.>>

Public Class Account

Private nam As String

Private SortCod As Integer

Private AccNumber As Integer

Public Sub New(ByVal name As String, ByVal SortCode As Integer, ByVal AccountNumber As Integer)

nam = name

SortCod = SortCode

AccNumber = AccountNumber

End Sub

Public Property Name() As String

Get

Return nam

End Get

Set(ByVal Value As String)

nam = Value

End Set

End Property

Public Property SortCode() As Integer

Get

Return SortCod

End Get

Set(ByVal Value As Integer)

SortCod = Value

End Set

End Property

Public Property AccountNumber() As Integer

Get

Return AccNumber

End Get

Set(ByVal Value As Integer)

AccNumber = Value

End Set

End Property

End Class

Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

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.>>

http://forums.microsoft.com/MSDN/Search/Search.aspx?words=access+database&localechoice=9&SiteID=1&searchscope=forumgroupscope&ForumGroupID=10

Sql database.>>

http://forums.microsoft.com/MSDN/Search/Search.aspx?words=sql+database&searchKey=&lcid=1033&searchscope=forumgroupscope&siteid=1&ForumID=-1&ForumGroupID=10&GoButton=+Go+

Database.>>

http://forums.microsoft.com/MSDN/Search/Search.aspx?words=database&searchKey=&lcid=1033&searchscope=forumgroupscope&siteid=1&ForumID=-1&ForumGroupID=10&GoButton=+Go+

Sorry i can't give a full example myself.

--

Dim lblArray(32) As Object

Dim index As Integer

Dim 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.Load

lblArray(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

Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5

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

Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...