Need Help with


I am trying to insert data from a text box into my database but I am not really sure how I do this.

I done select statements before but I never tried insert data from my website into a database.

 Also does anyone have a good site or book that shows examples how do do stuff like insert,update and stuff like that with C# examples.



Ms Sql 2005, VS 2008 SP1, Windows XP Pro.
1/2/2008 6:47:38 AM 16182 articles. 0 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 54

check out the link below, you might get some help..

Simple ADO.NET Database Read, Insert, Update and Delete using C#.. Free source code and programming articles

Manipulating Data (ADO.NET)

Calling Stored procedures in C# Programming

hope it helps./. 

[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"

Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
1/2/2008 1:25:47 PM


Thanks I been trying some stuff but it does not work I not sure why though.

I have 3 text boxes and one button. I insert some data into the textbox and hit the button. It should then insert the data into the database however it does not. If I take that same information and stick in the table myself it allows the data to go in.



using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)

        SqlDataSource dataSource = new SqlDataSource();
        dataSource.ConnectionString = getConnection().ToString();
        dataSource.InsertCommandType = SqlDataSourceCommandType.Text;
        dataSource.InsertCommand = "INSERT INTO QuickLinks (UserID, CharacterName, CharacterImagePath) VALUES (@UserID,@CharacterName,@CharacterImagePath)";
        dataSource.InsertParameters.Add("UserID", txtuserID.Text);
        dataSource.InsertParameters.Add("CharacterName", txtCharacter.Text);
        dataSource.InsertParameters.Add("CharacterImagePath", txtImage.Text);

    protected SqlConnection getConnection()
        /* Declares the connections for the database */
        SqlConnection conn;
        /*Grabs the connection string */
        string connectionString = ConfigurationManager.ConnectionStrings["Japanese"].ConnectionString;
        conn = new SqlConnection(connectionString);
        return conn;



<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

"-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">Untitled Page

    "form1" runat="server">
"txtuserID" runat="server">UserID "Button1" runat="server" onclick="Button1_Click" Text="Button" />

"txtCharacter" runat="server">character
"txtImage" runat="server">image
"GridView1" runat="server"> "SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:JapaneseConnectionString %>" SelectCommand="SELECT * FROM [QuickLinks]"> Database trying to insert into
 LinkID int - PK
UserID - uniqueidentifier
CharacterName - varchar(5)
CharacterImagePath -varchar(50)
Format of the initialization string does not conform to specification starting at index 0. 
Also I ran into one of my old instructions and asked him about what book I should learn and he told me that I should move to LinQ instead since it is taking over for Should I do this and switch since thats the new thing?


Ms Sql 2005, VS 2008 SP1, Windows XP Pro.
1/3/2008 2:43:52 AM

Try to change your codes with this below

        dataSource.InsertParameters.Add("@UserID", txtuserID.Text);
dataSource.InsertParameters.Add("@CharacterName", txtCharacter.Text);
dataSource.InsertParameters.Add("@CharacterImagePath", txtImage.Text);

 Let me know if this works..


"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
1/3/2008 4:50:27 AM


Try to change your codes with this below

        dataSource.InsertParameters.Add("@UserID", txtuserID.Text);
dataSource.InsertParameters.Add("@CharacterName", txtCharacter.Text);
dataSource.InsertParameters.Add("@CharacterImagePath", txtImage.Text);

 Let me know if this works..


 Nope I get the same error.

Also what do u guys think about learning linq instead of

Ms Sql 2005, VS 2008 SP1, Windows XP Pro.
1/3/2008 4:59:35 AM

If you just wanted to insert data into your DB then you can try this way

    private void Addnew()

                SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["YOUR Connection String"]);

                sql = "INSERT INTO QuickLinks (UserID, CharacterName, CharacterImagePath) VALUES (TextBox1.Text,TextBox2.Text,TextBox3.Text)";

                SqlCommand cmd = new SqlCommand(sql, conn);



    protected void Button1_Click(object sender, EventArgs e)




"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
1/3/2008 5:57:47 AM

Ok I figured out the problem.

 dataSource.ConnectionString actually wanted ConfigurationManager.ConnectionStrings["Japanese"].ConnectionString and not getConnection() what contained that. But since that returned a  SqlConnection object and not a string when it tried to cast it to a string it gave back its name.

Ms Sql 2005, VS 2008 SP1, Windows XP Pro.
1/3/2008 6:56:01 AM

Similar Artilces:

ADO.NET Visual Studio 2005 Install Help!, ADO.NET Missing
 Hi everyoneI have a real annoying problem, I have installed Visual Studio 2005 with C#,C++,Web Applications.. Before I installed VS2005 I made sure I had all the .Net Download from 1.1 to 3.5 with the Service Packs, I also Installed a VS2005 Patch that was around 430mb. I have tried this on 3 computers, two of XP and 1 vista.I need ADO.NET Functionality, When I choose to create a Web Application in C#, I require the ADO.NET Entity Data Model as it will allow for a graphical interaction with a SQL db. However When I Choose Add New Item in Solution explorer there is no ENtity Mode...

Needed help in ....
Hi friends... I got  the below step in one website for viewing the details of table using ADO.Net data xml... To view Atom (the default format returned by an ADO.NET Data Service) in Internet Explorer, you must first ensure that Feed Reading View is turned off. This can be done on the Content tab of Tools | Internet Options   But the problem is i cant find the feed reading view in content tab of internat option in tools. wat should i do can any one help me in resolving it pls.......Thanks,Sravan Kumar.  in content you have to click on the "settings&quo...

ADO to ADO.NET help
Hi, I am converting application ASP to ASP.NET.What is the equivalent code in ADO.NET. For each F in RS.Fields FieldName = F.Name Next Thanks, Nate If it is forward only, then you can use datareader for more info on this, check below link Datareader on MSDN Hope it helps!Sreedharhttp://www.w3coder.orgweblog

ADO.NET Oracle help needed!
I'm just starting with ADO.NET and ASP.NET. I have been working with ADO for a while now, but I seem to be stuck on ADO.NET. I don't understand why the following code brings back an error message saying "Value cannot be null. Parameter name: Dataset." and highlights the DA.Fill(DS,"grade") line, saying that is where the problem is. Can anyone help me figure this out? Most of my readings on ADO.NET talk about SQLserver...not exactly much help there. Thanks! Dim DS As DataSet Dim MyConnection As OleDBConnection Dim DA As New OleDBDataAdapter ...

Innovation to ADO.NET
Matisse Software Inc. provides its native ADO.NET Data provider for Matisse 6.0, the Database for .NET. Matisse Software has pushed the envelope of Microsoft ADO.NET architecture and extended it into a powerful Object Access Services component for .NET. Matisse’s extension of ADO.NET demonstrates that ADO.NET can evolve beyond the Microsoft architecture to benefit .NET developers. Unlike the standard ADO.NET data provider, which returns data in a table format to integrate seamlessly with relational products, Matisse has extended the ADO.NET architecture to return data in an object format....

Does .NET map calls for ADO to ADO.NET?
Hello,We are trying to troubleshoot some DB problems from COM objects that call ADO. I heard that when ADO is loaded inside of a COM object by a .NET app, that .NET intercepts the call and re-maps those calls over to ADO.NET. This seems untrue to me, given the nature of ADO.NET being a totally separate technology.Does anyone know for sure whether this does or does not occur?The problem we are seeing is actually almost identical in symptoms to this:"FIX: Data Queries Sporadically Return Empty Recordsets" Literally, this is what...

I am writing a database interface and I would like to know whether a VB6 interface using ADO or a VB.NET interface using ADO.NET would be faster in terms of just performing database operations. Is there an explanation for this, and what is the magnitude of the difference? Thanks in advance!... or/and
Hi, Can work with Sybase's or are they not compatible with each other. We have two separate groups of developers, one group develops web apps using ASE as the back end for the data, so they use a combination of Visual Studio ..NET and Sybase's to do their work. We have another group that develops client/server apps using Powerbuilder, but since 80% of their work is in writting reports using Powerbuilder, I was wondering if they could use a combination of and to put make these reports available on the web through ...

Where is the ADO.NET Sybase driver for .NET 1.1 and .Net 2.0?
Hi All Does anyone know where I can get the Sybase drivers for ADO.NET for both versions, 1.1 and 2.0/3.0? Cheers Chris Burrell Hi Chris, There is no release of ASE ADO.NET Provider 2.0 (I assume you refer to ASE provider, not ASA - if ASA please port to sybase.public.sqlanywhere.general). For the 1.1 Provider: It is available in the ASE SDK for windows or the PC Client CDRom included with ASE product. On the SDK its available as 12.5.1 and 15.0 On ASE PC Client I think 12.5.1 is part of ASE 12.5.X and 15.0 is part of ASE 15.X 2.0 provider should release som...

HELP needed with ADO net and data binding to Gridview etc
 Hello,  i am using Visual Web Developer, SQL Express, and C sharp All I want to do at this stage is write the code to display a gridview on my page using know it can be done through the wizards but I want to go backstage and piece it together!!But I get a error message each time, mainly " CS1009: Unrecognized escape sequence" Is it possible someone could show me how this can be done. I know a litte about the SQL connection and Command and then reader but lost when it comes to data bindingto web forms data source controls like data grid or list.&n...

------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

Sybase ADO.NET 2.0 data provider, Need Help plz
Hello everyone, I'm looking for sybase ADO data provider for net 2.0, but sybase don't realease it yet :(. Is there somebody who using another data provider with Sybase Ase 12.5? I don't want use ODBC drivers. I need only provider which have the same functionality as SQL data source with Microst SQL server. Thanks everybody for help. Denzo Try the link below for .NET provider vendors.  Hope this helps. regards,Gift Peddie very fast..and easy to implement...but a bit pricey....

Urgently need help with Net::SSH::Perl / Math::Pari / @INC and loadable objects
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there! This is my first posting to this mailing list, so plz don't flame me - - ok ;-) Please send your responses to: Rows will probably wrap. I am trying to use the Net::SSH::Perl module with Perl 5.6.1 on a i686 RH 6.2 Linux box. My code is quite basic so far (mostly from Net::SSH:Perl manpage since I want to start to be able to establish a connection before I develop any further): #!/usr/bin/perl -w use Net::SSH::Perl; use strict; my ($ssh,$host,$user,$pass,$stdout,$stderr,$exit,$cmd,$... and .net 2.0
Does anyone know if there has been any notable changes to ADO.NET in .NET 2.0 in the areas of data access (both reads and writes) except for the new SqlDataSource and equivalent user controls? Try these links for  tutorials. Hope this helps. regards,Gift Peddie...

Web resources about - Need Help with -

The Real Climate Crisis that the Global Warming Scammers are Ignoring
By Karl Denninger No, folks, it's not "globull warming." I know, I know, we're all going to drown if we don't "stop" it. Of course this means ...

Emanuel dismisses top cop Garry McCarthy amid pressure for change
Chicago Tribune Emanuel dismisses top cop Garry McCarthy amid pressure for change Chicago Tribune Garry McCarthy was appointed Chicago police ...

Cyber Monday sales top $3 billion as discounts spur buyers
Shopping through mobile devices soared on Cyber Monday, accounting for more than a quarter of the $3 billion in sales, but many online retailers ...

The Alamo Drafthouse Just Opened a ‘Star Wars’-Themed Movie Theater…in Nebraska
Up until today, you probably had no reason to go to Omaha, Nebraska. But that will change once you see the new theater the Alamo Drafthouse has ...

Ted Cruz buys his rubbers from a vending machine and other fun things the GOP said today
Hello! Welcome to what should really be a regular installment here at Grist, Shit Republicans Running For President Say . Today, we have a double ...

Hillary Clinton's logo accidentally puts Rosa Parks in the back of a bus
Former Secretary of State Hillary Clinton spoke Tuesday on the anniversary of Rosa Parks' Dec. 1, 1955 arrest for refusing to give her bus seat ...

Is WhatsApp Blocking Links From Telegram?
Is WhatsApp blocking links to rival messaging application Telegram ? co-founder and CEO Bernhard Hauser reported in a blog post that ...

The complete gift guide for Mark Zuckerberg's new baby
The holidays are just around the corner, and Mark Zuckerberg and Priscilla Chan's daughter Max was born just in time to celebrate But what do ...

Tuesday Night News Brief: ‘Raped by Bear’, Chris Hemsworth, World AIDS Day, ‘Deadpool’
BLOG. Matt Drudge got all excited about the prospect of Leonardo DiCaprio getting raped by a bear in his new film The Revenant . RIGHT WING ...

This Intense Short Film About Virtual Reality Is Already in the Works as a Feature
“Virtual reality, to me, is the only reality.” So begins Uncanny Valley , a short from Argentina’s Federico Heller that’s on the fast track to ...

Resources last updated: 12/2/2015 12:38:56 AM