Hello everyone!
i have problem in inserting data in my database from textbox, i m using c#.
the code in .aspx.cs file is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlDataAdapter da = new SqlDataAdapter();
SqlConnection sqlcon = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Qarni\My Documents\Visual Studio 2008\WebSites\database-example\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand("INSERT INTO TABLE1 (Name, Address, Email, Phone, Dob) VALUES ('"+nametbox.Text+","+addtbox.Text+","+mailtbox.Text+","+phonetbox.Text+","+dobtbox.Text+"')");
sqlcmd.Parameters.AddWithValue("@Name", nametbox.Text);
sqlcmd.Parameters.AddWithValue("@Address", addtbox.Text);
sqlcmd.Parameters.AddWithValue("@Email", mailtbox.Text);
sqlcmd.Parameters.AddWithValue("@Phone", phonetbox.Text);
sqlcmd.Parameters.AddWithValue("@Dob", dobtbox.Text);
lbl.Visible = true;
sqlcon.Close();
}
}