Ankit Kumar

Ankit Kumar

  • NA
  • 159
  • 48.3k

Data Insertion in data base

Oct 8 2015 3:49 AM
Hey guys,
                  can any one help me please. i am facing error while inserting data in database using asp .net.
                   Here is the complete code
                   
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();
}
}
}
 

Answers (5)