error:System.NullReferenceException: Object reference not set to an instance of an object. at student._Default.clicked(Object sender, EventArgs e)
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace student { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void clicked(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["stdConnectionStrings"].ConnectionString); con.Open(); string user = "select count(*)from the stdtable where std_name='" + TextBox1.Text + "'"; SqlCommand com = new SqlCommand(user, con); int a = Convert.ToInt32(com.ExecuteScalar()); if (a == 1) { Response.Write("user already exist"); } string insertQuery = "insert into stdtable (std_name,roll,std_address) values (@std_name,@roll,@std_address)"; com.Parameters.AddWithValue("@std_name", TextBox1.Text); com.Parameters.AddWithValue("roll", TextBox2.Text); com.Parameters.AddWithValue("@std_address", TextBox3.Text); com.ExecuteNonQuery(); Response.Redirect("stdadmin.aspx"); Response.Write("registration succescesfull..."); con.Close(); } catch (Exception ex) { Response.Write("error: " + ex.ToString()); } } } }
ConfigurationManager.ConnectionStrings["stdConnectionStrings"].ConnectionString
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)