I get an error, and in the local window, I see null for both conSettings and connectionString. I have the right to say that the ConfigurationManager is null and I need to create a new object. Maybe I'm using Access and maybe something was missing in the App.config file. Can someone help me in solving this problem please. Thanks in advance.
App.config File ...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MyDBConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\...\Database1.mdb"/>
</appSettings>
</configuration>
File Form.cs ...
private void btnShow_Click(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string connectionString = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString;
try
{
con = new OleDbConnection(connectionString);
con.Open();
cmd = new OleDbCommand("SELECT * FROM Table1", con);
objReader = cmd.ExecuteReader();
while (objReader.Read())
{
txtID.Text = ds.Tables[0].Rows[rno][0].ToString();
CBAgeGroup.Text = ds.Tables[0].Rows[rno][1].ToString();
CBGender.Text = ds.Tables[0].Rows[rno][2].ToString();
CBCrimOffen.Text = ds.Tables[0].Rows[rno][3].ToString();
if (ds.Tables[0].Rows[rno][4] != System.DBNull.Value)
{
photo_aray = (byte[])ds.Tables[0].Rows[rno][4];
MemoryStream ms = new MemoryStream(photo_aray);
pictureBox1.Image = Image.FromStream(ms);
}
txtCV.Text = ds.Tables[0].Rows[rno][5].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
I was recommended to use App.config.
VS 2010 C # MS Access 2003
UPDATE 1
Now my App.config looks like this ...
<configuration>
<ConnectionString>
<add key="MyDBConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Raj\Education\C_Sharp\Test1\Database1.mdb"/>
</ConnectionString>
Now I get the error ... "Failed to initialize the configuration system." I look at it now on Google.
Update 2
Tried ...
<configuration>
<connectionStrings>
<add name="MyDBConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\...\Database1.mdb"/>
</connectionStrings>
</configuration>
" , "
3
<configuration>
<connectionStrings>
<clear />
<add name="MyDBConnectionString"
providerName="System.Data.OleDb" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Source=\Database1.mdb" />
</connectionStrings>
3 . . , System.Configuration;
, , VS 2010 Access 2003. App.config . , SQL Server . . .