Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET Webforms (insert, update, and delete records ) SQL Server and Visual Studio.net

Reply
Thread Tools

ASP.NET Webforms (insert, update, and delete records ) SQL Server and Visual Studio.net

 
 
kennethgrice@yahoo.com
Guest
Posts: n/a
 
      05-20-2005
Hi,

I am new to ASP.net and visual studio.net.

I have created a new ASP.NET Web Application and have started with a
simple form.

I have created a simple test database that will store a person's first
and last name and their SSN. The primary key is an autonumbered field.

So I have made a connection in Visual Studio with the sql data adapter
and have dragged 3 text boxes on the web form.

For each text box, I have set the data source to be the field in the
database or (dataset)

So now I have dragged a button on to the form.

Do I put the insert, update, and delete code in the button properties?

Can visual studio.net generate the code to do this, or do I manually
have to write to code to do this. If it has to be done manually, could
someone please post sample code on how to do this?

My text box names are f_name, l_name, and ssn.
And the fields in the database are labeled the same way.


Thanks in advance for any help.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TXJNaWtl?=
Guest
Posts: n/a
 
      05-20-2005
Hi Kenneth,

One way to do this is to create SQL Stored Procedures which will actually
perform the Insert/Update/Delete against the data, and then simply execute
them from your ASP.NET application.

If you're not familiar with SQL Stored Procedures, here's an example of what
one would look like that updates the f_name field of your database...
-------------------------------------------------------
CREATE PROCEDURE dbo.spf_nameUpdate
(
@ID varchar(50),
@f_name varchar(4)
)
AS
SET NOCOUNT OFF;

UPDATE TableName
SET f_name = @f_name
WHERE (ID = @ID)
GO
-------------------------------------------------------

After you've created the Stored Procedure, you can then add a SQLCommand
object to your webform (available in the toolbox, under the data tab.) Upon
adding the SQLCommand to your webform, you can simply follow the wizard to
specify the database and stored procedure it should connect to.

HTH,
Mike

"" wrote:

> Hi,
>
> I am new to ASP.net and visual studio.net.
>
> I have created a new ASP.NET Web Application and have started with a
> simple form.
>
> I have created a simple test database that will store a person's first
> and last name and their SSN. The primary key is an autonumbered field.
>
> So I have made a connection in Visual Studio with the sql data adapter
> and have dragged 3 text boxes on the web form.
>
> For each text box, I have set the data source to be the field in the
> database or (dataset)
>
> So now I have dragged a button on to the form.
>
> Do I put the insert, update, and delete code in the button properties?
>
> Can visual studio.net generate the code to do this, or do I manually
> have to write to code to do this. If it has to be done manually, could
> someone please post sample code on how to do this?
>
> My text box names are f_name, l_name, and ssn.
> And the fields in the database are labeled the same way.
>
>
> Thanks in advance for any help.
>
>

 
Reply With Quote
 
 
 
 
GreggTB
Guest
Posts: n/a
 
      05-20-2005
If you eventually want/need to write your own code for database tasks,
you really ought to check out Microsoft's Data Access Application
Block. The latest version is currently part of the Enterprise Library
but I'm using an Oracle-specific adaptation of the original, standalone
version and it works great. Definitely helpful when you're trying to
follow common coding standards. You can find details about it here...

http://msdn.microsoft.com/library/de.../html/daab.asp

 
Reply With Quote
 
elizas elizas is offline
Junior Member
Join Date: Jan 2010
Location: India
Posts: 29
 
      04-27-2010
Generally we write separate statements to INSERT UPDATE or DELETE data based on certain conditions. But now in SQL Server 2008 there is a new feature present called MERGE statement using which we can INSERT, UPDATE or DELETE record in one statement.

MERGE is a new feature which Microsoft has introduced with SQL Server 2008 that provides an efficient way to perform multiple DML operations. In previous version of SQL server, we had to write separate statements to INSERT, UPDATE or DELETE data based on certain conditions, but now using MERGE statement we can include the logic of such data modifications in one statement that even checks when the data is matched then just update it and when unmatched then insert it. One of the most imortant advantage of MERGE statement is all the data is read and processed only once.The MERGE statement internally works as an individual insert, update and delete statement within a single Merge statement.You need to specify the SOURCE and the TARGET table or query which should be joined together.
 
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
Help. Getting a An error has occurred while establishing a connectionto the server. When connecting to SQL Server 2005, this failure may be causedby the fact that under the default settings SQL Server does not allow remote aboutjav.com@gmail.com ASP .Net 0 05-03-2008 12:43 PM
Can't view webforms in design view in visual Studio 2005 Robert Smith ASP .Net 2 04-27-2008 12:40 PM
How to read an SQL Server into a ASP page and then change, add, delete and write it back to SQL Server Belinda ASP General 4 06-11-2004 12:16 PM
Delete records or update records Dan ASP General 1 05-10-2004 01:25 PM
How to Delete Old Records from an Excel File Using ASP.Net and Visual Basic .NET Mahesh Kumar ASP .Net 1 10-25-2003 08:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57