Scenario: i have a little programm that uses OleDb.connectio n to connect to
a database... the datasource is C:\programm Files\Database. mdb now i want to
change the datasource for the connection while i am reading the datasource
string from a file !!!! Cause the user want to put the database a place i
dont noe yet!!!(e.g a fileserver on the network!)
Code:
private void Form1_Load(obje ct sender, System.EventArg s e)
{
string Serverpath;
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using(StreamRea der sr = new StreamReader("S erverpath.txt") )
{
Serverpath = sr.ReadLine();
}
setpath(Serverp ath);
}
catch(Exception b)
{
MessageBox.Show ("File Could not be Read " + b);
}
label8.Text = Data_Connection .ConnectionStri ng;
}
private void setpath(string str)
{
Data_Connection .DataSource = str; // variable from textfile (path)
}
C# says this while i am compiling
C:\Documents and Settings\f28403 \My Documents\Visua l Studio
Projects\Window sApplication3\F orm1.cs(722): Property or indexer
'System.Data.Ol eDb.OleDbConnec tion.DataSource ' cannot be assigned to -- it
is read only
Is there anyone who can help me!!!
a database... the datasource is C:\programm Files\Database. mdb now i want to
change the datasource for the connection while i am reading the datasource
string from a file !!!! Cause the user want to put the database a place i
dont noe yet!!!(e.g a fileserver on the network!)
Code:
private void Form1_Load(obje ct sender, System.EventArg s e)
{
string Serverpath;
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using(StreamRea der sr = new StreamReader("S erverpath.txt") )
{
Serverpath = sr.ReadLine();
}
setpath(Serverp ath);
}
catch(Exception b)
{
MessageBox.Show ("File Could not be Read " + b);
}
label8.Text = Data_Connection .ConnectionStri ng;
}
private void setpath(string str)
{
Data_Connection .DataSource = str; // variable from textfile (path)
}
C# says this while i am compiling
C:\Documents and Settings\f28403 \My Documents\Visua l Studio
Projects\Window sApplication3\F orm1.cs(722): Property or indexer
'System.Data.Ol eDb.OleDbConnec tion.DataSource ' cannot be assigned to -- it
is read only
Is there anyone who can help me!!!
Comment