i am getting "Unhandled Null referenceException "--object reference not set to an instance of an object at below mentioned code in bracket
(return System.Configuration.ConfigurationManager.ConnectionStrings["unitmoduleconnectionstring"].ConnectionString)
and below is the total code
help me to get out of this bug....
namespace TIMS
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
}
private void itemmastBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.itemmastBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.unitmoduleDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'unitmoduleDataSet.itemmast' table. You can move, or remove it, as needed.
this.itemmastTableAdapter.Fill(this.unitmoduleDataSet.itemmast);
}
public string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["unitmoduleconnectionstring"].ConnectionString;
}
System.Data.SqlClient.SqlConnection con;
System.Data.SqlClient.SqlDataAdapter da;
System.Data.SqlClient.SqlCommand cmd;
DataSet ds1;
int inc = 0;
private void BtnSave_Click(object sender, EventArgs e)
{
{
InsertInfo();
}
}
private void InsertInfo()
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(GetConnectionString());
string sql = "INSERT INTO itemmast (itemcode,itemName,iunitmeasure,itemtype,Createdby,Unitcode) VALUES (@Val1,@Val2,@Val3,@Val4,@Val5,@Val6)";
try
{
con.Open();
cmd = new System.Data.SqlClient.SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@Val1", Itemcode.Text);
cmd.Parameters.AddWithValue("@Val2", ItemName.Text);
cmd.Parameters.AddWithValue("@Val3", UnitMeasure.Text);
cmd.Parameters.AddWithValue("@Val1", Itemtype.Text);
cmd.Parameters.AddWithValue("@Val1", Username.Text);
cmd.Parameters.AddWithValue("@Val1", MDIunitcode.Text);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show("There is an Error" + ex);
}
finally
{
con.Close();
MessageBox.Show("Connection Closed");
}
}