parthiban karnan

parthiban karnan

  • NA
  • 549
  • 101.3k

ERROR:The ConnectionString property has not been initialized

Apr 19 2013 2:30 AM
I GET THE ERROR:

The ConnectionString property has not been initialized.
==================================================

public partial class j : System.Web.UI.Page
{
   // SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString);
    int intcount;
    SqlCommand cmd;
    string sqlstr;
    int count;
    String strConnString = ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString;
    SqlConnection con = new SqlConnection();
    



    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "JOINMAX";
        cmd.Parameters.Add("@NAME", SqlDbType.VarChar).Value = txtName.Text.Trim();
        cmd.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value =txtEMAIL.Text.Trim();
        cmd.Parameters.Add("@PHONENO", SqlDbType.VarChar).Value =txtPHONE.Text.Trim();
        cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
        cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;



       
        
        
        cmd.Connection = con;
        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
              string message = (string)cmd.Parameters["@ERROR"].Value;
              Label1.Text = "Record inserted successfully";
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            
            con.Close();
            con.Dispose();
        }


Answers (6)