parthiban karnan

parthiban karnan

  • 1.3k
  • 549
  • 72.2k

ExecuteNonQuery: Connection property has not been initialize

Apr 19 2013 4:44 AM

String strConnString = ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString;

        //SqlConnection con = new SqlConnection();

        protected void btnSave_Click(object sender, EventArgs e)
        {

          SqlConnection con = new SqlConnection(strConnString);
            con.Open();
         //   con.ConnectionString = new SqlConnection(strConnString);
            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.ExecuteNonQuery();
            //  Label1.Text = "Record inserted successfully";
string message = (string)cmd.Parameters["@ERROR"].Value;
            con.Close();
        }
    }

}

Answers (4)