473,379 Members | 1,216 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

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.

Nov 19 '05 #1
2 3860
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

"ke**********@yahoo.com" 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.

Nov 19 '05 #2
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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
1
by: alan | last post by:
in my project there are 5 textbox : tbOrderid, tbSeqNum, tbFoodCode, tbFoodDesc and tbPrice 9 button: btInsert, btdelete, btUpdate, btClear, btBind, btFirst, btPrevious, btNext and btLast i...
9
by: DraguVaso | last post by:
Hi, I'm writing a VB.NET application who has to insert/update and delete a whole bunch of records from a File into a Sql Server Database. But I want to be able to knwo the 'result' of my ctions....
4
by: 3Cooks | last post by:
I have a windows application written in Visual Basic 6.0 that is going to be redeveloped in dotNET. We are trying to decide if we should deploy using Webforms or Winforms and I need advice from...
5
by: Robert | last post by:
I am very new to .net and asp.net. I am trying to design an intranet page that has a SQL Server 2000 database. I understand how to connect to the data but am getting very confused on how to...
8
by: nano2k | last post by:
Hi Shortly, I keep invoices in a table. Occasionally, someone will fire the execution of a stored procedure (SP) that performs several UPDATEs against (potentially) all invoices OLDER than a...
0
by: troydixon | last post by:
Hello, I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the...
2
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi, I have just installed visual studio 2005 professional edition (evaluation version). However it will not allow me to view webforms in a website project in design view. I can just see the HTML...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.