Data insertion problem in sql from textbox

Discussion in '.NET' started by faniccj, Feb 12, 2011.

  1. faniccj

    faniccj

    Joined:
    Feb 11, 2011
    Messages:
    2
    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
     
    faniccj, Feb 12, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bighead4694@hotmail.com

    how to code to avoid SQL insertion attacks

    bighead4694@hotmail.com, Feb 15, 2005, in forum: Java
    Replies:
    44
    Views:
    4,051
    Lee Fesperman
    Mar 16, 2005
  2. narasimha
    Replies:
    3
    Views:
    476
    John Harrison
    Jul 2, 2004
  3. DurumDara
    Replies:
    1
    Views:
    331
    Roger Binns
    Apr 8, 2006
  4. Lars

    SQL INsertion problem

    Lars, Feb 14, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    313
  5. Sumanta Das
    Replies:
    2
    Views:
    174
    Robert Klemme
    Jul 4, 2008
Loading...

Share This Page