Constant expression is required?

glw1988

New member
Joined
Apr 21, 2010
Messages
4
Programming Experience
1-3
Hi,

I have created a program that creates a blank database in a users account (each user has a seperate folder when registered) by pressing a command button, i have got it to create the database but when i try to populate it with a table to go to the correct folder i get an error

Constant expression is required

the code im using for this is:

VB.NET:
Const strConnection As String = ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                 "Data Source=E:\Accounts\" + txtRegUsername.Text + "\ViewBills.accdb")
 
It's probably not a god idea to use a separate database for each user. A better idea would generally be to use a single database with a User table, which is then related to the other tables in the database so each user gets their own data.

As for the problem, does it really make sense to declare a constant whose value will vary for each user? The whole point of a constant is that its value is constant, i.e. doesn't change. You should be using a variable instead.

Also, is it really safe to hard-code the path like that? What if the user doesn't have an E: drive? What if the administrator wants to change the configuration so the data in on a different drive? Should you really have to recompile the program to simply move a data file?
 
Back
Top