.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

simple insert into SQL

Posted By:      Posted Date: September 13, 2010    Points: 0   Category :ASP.Net
I'm going to betray my "newbie"-ness here in a big way, but that's alright. Am getting the hang of displaying data using the FormView, GridView, etc, following Scott Mitchell's excellent tutorial. But what I need to do now is create a form that doesn't display any records, but simply allows a web page user to enter a new record, validate the data, insert the data in an SQL table as a new record, and display a confirmation to the user (and send an email confirmation). Is there a tutorial somewhere that can walk me through this? I have the SQL database ready to go, have a dataset and Table Adapter with my insert query all set in my Visual Studio 2010 Web Application Project, have the DataSource established on the page, have the text boxes for the user input and a submit button. I just need a little guidance on how to tie everything together. Have searched in vain for a step-by-step online somewhere. If you could point me to one, I'd be much obliged. Or if some saint has the patience to hold my hand and walk me through the final steps here, I'd be eternally grateful. 

View Complete Post

More Related Resource Links

Simple LINQ to SQL Insert


I have this:

protected void btnInsert_Click(object sender, EventArgs e)
        lusHmoobDataContext lusHmoobDC = new lusHmoobDataContext();

        lusHmoob lhbLusHmoob = new lusHmoob();

        lhbLusHmoob.wordID = Guid.NewGuid();
        lhbLusHmoob.word = txtWord.Text;
        lhbLusHmoob.usage = txtUsage.Text;
        lhbLusHmoob.hmgTrans = txtEnglishTrans.Text;
        lhbLusHmoob.engTrans = txtEnglishTrans.Text;
        lhbLusHmoob.originate = txtOriginate.Text;
        lhbLusHmoob.modDate = DateTime.Now.ToLongDateString();
        lhbLusHmoob.insertDate = DateTime.Now.ToLongDateString();


And I kept getting this error even though when I compiled, there is no error.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'lusHmoob' does not contain a definition for 'wordID' and no extension method 'wordID' acc

Simple insert to test with...

Is this the most efficient way to run this code?  Basically just want to insert 100000 records into a table incrementing as it goes.
set nocount on

declare @i int;
set @i = 0
while ( @i < 100000 )
  insert into DebtorIDTest ( DebtorID ) VALUES ( @i )
  set @i = @i + 1

The reason I ask is when running this on SQL Server 2000 it runs about 2 - 3 seconds faster than when I run it on 2008.  Just wondering if perhaps there is a "newer" way of doing this.  Just running it from the Mgmt Studio.

Thanks in advance!

Simple Insert ado.net


Hi all,

I am just trying to do a simple insert into multiple tables but it doesnt seem to be working. Here is the code


        string inStrAl = "INSERT INTO [Album] ([Album#], [Artist#], [AlbumName]) VALUES ('" + albumState + "', '" + albumState + "', '" + TXTAlbum.Text + "')";
        string inStrAr = "INSERT INTO [Artist] ([Artist#], [ArtistName]) VALUES ('" + artistState + "', '" + TXTArtName2.Text + "')";
        string inStrLa = "INSERT INTO [Label] ([Label#], [Artist#], [LabelName]) VALUES ('" + labelState + "', '" + artistState + 

Insert value using Table Value Functions

a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

Creating a Simple Class in C#

The second article in the C# Object-Oriented Programming tutorial describes how classes are created in C# and how behaviour, in the form of publicly visible and private, hidden methods can be added. This demonstrates some of the uses of encapsulation

Insert Rows with a GridView

In ASP.NET version 1.x, I used the footer on the DataGrid control to insert new rows by placing a series of TextBox, DropDownLists, CheckBoxes etc. controls on it and then handling a save button. This also works with the GridView in version 2.0 but with one major exception: if your data source is empty, the GridView will hide your footer (and header) and only display the EmptyDataText.

A Simple and Extensible Radio Button Style GridView

The GridView is one of the significant controls in ASP.NET 2.0 and later versions. No doubt it reduces a lot of work time. However, customizing the GridView control is not an easy task. For example, it's hard to add a radio button column to the GridView. This article demonstrates the reason why a radio button column cannot act as normal and how to create a simple and extensible radio button GridView.

Silverlight Simple Animation

Silverlight has several built in techniques for animating controls. Many of these technologies are particularly useful for creating simple animations meant to decorate a web page with eye catching movement that draws the reader's attention. In this post I will skip over these decorative technologies, and instead show how to create a simple animation using a technique similar to those used in many games.

SqlCommand.ExecuteNonQuery() returns -1 when doing Insert / Update / Delete

Sometimes you end up with a return value of -1 when using the SqlClient.SqlCommand.ExecuteNonQuery method.

Why is that?

Well, the ExecuteNonQuery method is there for statements for changing data, ie. DELETE / UPDATE /INSERT, and the returned value are the number of rows affected by that statement.

When checking the documentation we can see that there are some conditions that return -1.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.

When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of

rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

I thought this would be simple... Trying to create a login does an ajax check before submit


I have the standard .net login control that is working.  (Still learning .net after 15yrs of classic)

What I want to do is OnButtonClick run a javascript function (to do an ajax call to the db to check if login is valid or not) and if it returns true, then submit the form normally, else don't submit. The piece that I can't figure out, is how to correctly override the default click even to hit my JS routine and then submit the form properly afterwards.

Thanks ahead of time

Insert Error not helpful



I am using VS2010

When I try to updated or insert a record in my User table I am getting an error that does not make sense to me and I cannot figure out what is wrong.

Also, when I try to insert a new record I get a validation error saying that the Id is required. However it is an identity field in the db so it should not be necessary to send it to the server.

Could you please shed some light?


An error has occurred.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.Web.UI.WebControls.EntityOperationException: An error has occurred.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace:

[EntityOperationException: An error has occurred.]
   Microsoft.Web.UI.WebControls.DomainDataSourceView.PerformCudOperation(ChangeSetEntry operation, Action`1 operationPerformingEvent, Action`1 operationPerformedEvent) +331
   Microsoft.Web.UI.WebControls.DomainDataSourceView.UpdateObject(Object oldEntity, O

Detecting Edit or Insert Page


I am coding a .cs file that handles the metadata for a particular table. I am putting a custom validation that allows me to update or insert only if the PubMedID is not already in the database. This would be easy except that the PMID should also be allowed to be null as some of the references in the database were not from PubMed. So i perform a query on the database to see if there is already an identical PMID in the database. This works great when using Insert. However, when using Edit, it does not. The PMID is already in the database because the one currently being edited has the same PMID!!! So I know exactly how to change my query etc. However, I do not know how to tell from inside this Edit/Insert agnostic page, which one it is being called from. Thanks for your help! 

how To Insert the single quotes in sqlcommand in asp.net


Hi all

    i am developed on simple user registeration application in that i gave  address field .when i am trying to enter something like this (1st main,b'lore) but wont take while inserting.

my query is

sqlcommand cmd=new sqlcommand("insert into registeration_form(name,address)values('"+txtname.text+"','"+txt_address+"')",con);

how can i pass the  quotes also to my query please if any one know reply me.


G Dinakaran

Insert data to Excel using OLEDB



I am trying to insert data to Excel Document using OLEDB as follows:-

 sql = "Insert into [MyFirstSheet$] (" + Title1 + "," +Title2 + "," + Title3 + ") 
values('" + Value1 + "','" + Value2 + "','" + Value2 + "')";
myCommand.CommandText = sql;

 sql = "Insert into [MyFirstSheet$] (" + Title1 + "," +Title2 + "," + Title3 + ") 

values('" + Value1 + "','" + Value2 + "','" + Value2 + "')";

myCommand.CommandText = sql;


But, the Title1 ,Title2, Title3 are in the 3rd row of the Excel Document. So, the data is not inserted.

How to insert Image (jpeg) into MS Word Programmatically using VB.NET


Hi there,

Can someone help me on How to insert Image (jpeg) into MS Word Programmatically using VB.NET..not C#.NET??? Sad

I could hardly find any articles for the coding. Preferably using Bookmark...can i have the sample code.



Easy Async: Build Concurrent Apps From Simple F# Expressions


In this article, the author explores how the F# language helps you create asynchronous function libraries that can be called seamlessly from any other .NET-compliant language.

Chance Coble

MSDN Magazine October 2008

Wicked Code: Silverlight Page Turning Made Simple


As we'll show, with just a few lines of JavaScript you can build a general-purpose framework for incorporating page turns into Silverlight 1.0 apps.

Jeff Prosise

MSDN Magazine May 2008

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend