Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Data insertion problem in sql from textbox

Reply
Thread Tools

Data insertion problem in sql from textbox

 
 
faniccj faniccj is offline
Junior Member
Join Date: Feb 2011
Posts: 2
 
      02-12-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure + sql server 2005 + insertion Sumanta Das Ruby 2 07-04-2008 04:03 PM
SQL INsertion problem Lars ASP .Net 2 02-14-2008 02:17 PM
Insertion (sql) bug in Py2.4 pySQLite 2.2 DurumDara Python 1 04-08-2006 10:44 PM
how to code to avoid SQL insertion attacks bighead4694@hotmail.com Java 44 03-16-2005 12:44 AM
Data Retrieval/Insertion Data Structure narasimha C++ 3 07-02-2004 09:38 AM



Advertisments