Data insertion problem in sql from textbox

Joined
Feb 11, 2011
Messages
2
Reaction score
0
Hello everyone!
i have problem in inserting data in my database from textbox, i m using c#.
the code in .aspx.cs file is

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;
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();



    }
}

i m getting no error msgs when i click on submit button, but data is not inserted in my database. kindly anyone tell me in details what the problem here? remember i m new in asp.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top