S
SurfCoder
Scenario: i have a little programm that uses OleDb.connection 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(object sender, System.EventArgs e)
{
string Serverpath;
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using(StreamReader sr = new StreamReader("Serverpath.txt"))
{
Serverpath = sr.ReadLine();
}
setpath(Serverpath);
}
catch(Exception b)
{
MessageBox.Show("File Could not be Read " + b);
}
label8.Text = Data_Connection.ConnectionString;
}
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\Visual Studio
Projects\WindowsApplication3\Form1.cs(722): Property or indexer
'System.Data.OleDb.OleDbConnection.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(object sender, System.EventArgs e)
{
string Serverpath;
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using(StreamReader sr = new StreamReader("Serverpath.txt"))
{
Serverpath = sr.ReadLine();
}
setpath(Serverpath);
}
catch(Exception b)
{
MessageBox.Show("File Could not be Read " + b);
}
label8.Text = Data_Connection.ConnectionString;
}
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\Visual Studio
Projects\WindowsApplication3\Form1.cs(722): Property or indexer
'System.Data.OleDb.OleDbConnection.DataSource' cannot be assigned to -- it
is read only
Is there anyone who can help me!!!