I got Error(object reference is not set to an instance of an object) following this Code in wpf

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I got Error(object reference is not set to an instance of an object) following this Code
data.cs
public SqlConnection con;
public void connection()
{


con = new SqlConnection(ConfigurationManager.ConnectionStrings["CharityManagement"].ConnectionString);
con.Open();
}
mainwindow.xaml
private void button1_Click(object sender, RoutedEventArgs e)
{
try
{

data db = new data();
db.sqlcmmd("insert into register values(" + System.Guid.NewGuid() + "," + txtname.Text + "," + txtdateofbirth.Text + "," + txtgender.Text + "," + txtdegree.Text + "," + txtcollege.Text + "," + txtdescription.Text + ")");
MessageBox.Show("saved successfully");
}
catch (Exception ex)
{



}
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="CharityManagement"
connectionString="Data Source=localhostMSSQLSERVER2008;Initial Catalog=reg;Persist Security Info=true; Uid=sa;Pwd=testuser"/>
</connectionStrings>
</configuration>
anu

View the full article
 
Back
Top