can any one help me please. i am facing error while inserting data in database using asp .net.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
SqlConnection con = new SqlConnection("");
protected void Button1_Click(object sender, EventArgs e)
{
string connection = "Data Source=127.0.0.1; Initial Catalog=test; Integrated Security=true";
con.ConnectionString=connection;
try
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into studentfeedback values @name, @email, @contact, @company",con);
cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = TextBox1.Text;
cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = TextBox1.Text;
cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = TextBox1.Text;
cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = TextBox1.Text;
if(Convert.ToBoolean(cmd.ExecuteNonQuery()))
{
Response.Write("<script>alert('Data Successfully Inserted')</script>");
}
}
catch (Exception exp)
{
Response.Write("<script>alert('" + exp.Message + "')</script>");
}
finally
{
con.Close();
}
}
}