Debug your code & find out which line contains the issue
What does Object reference not set to an instance of an object mean[
^]
EDIT
-------------------------------
Try this code
public partial class Default2 : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["registration"].ToString());
con.Open();
cmd = new SqlCommand("insert into values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')", con);
cmd.ExecuteNonQuery();
}
}
<connectionstrings>
<add name="registration" connectionstring="data source=.TEKPC26\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=registration.mdf;User Instance=true" providername="System.Data.SqlClient" />
</connectionstrings>
BTW avoid Sql injection attacks
SQL injection
SQL Injection Attacks and Some Tips on How to Prevent Them[
^]
SQL injection attacks[
^]
SQL Injection Knowhow[
^]
SQL Injection and Cross-Site Scripting[
^]
EDIT 2
-------------------------------------
muralikrishna53 wrote:
i was changed my code with your advice, but one error..
"Unrecognized configuration section connectionstrings"
Here an easy fix
Error Solution: Fix for ‘Unrecognized configuration section connectionStrings’ Error in ASP.NET 2.0[
^]