asp.net how to connect to a SQL Server2000 database
Source: Internet
Author: User
asp.net|server| Data | All right, here's a routine about ASP.net connection to the SQL Server2000 database.
Here to share with you:
asp.net connection SQL Server2000 database routines Detailed:
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.SqlClient"%>
<script laguage= "VB" runat= "Server" >
Sub Page_Load (sender as object,e as EventArgs)
Dim MyConnection as SqlConnection
Dim MyCommand as SqlCommand
Dim DS as DataSet
' 1.connect to SQL Server
MyConnection = New SqlConnection ("Server=localhost;database=pubs;uid=ueytjdf;pwd=doekdf")
Myconnection.open ()
la1.text= "Connection opened!"
' 2.Create a table
mycommand = New SqlCommand ("CREATE TABLE [test] ([ID] [int] IDENTITY (1, 1) not NULL, [name]
) ", MyConnection)
Mycommand.executenonquery ()
la2.text= "New table created!"
' 2 Add record
mycommand = New SqlCommand ("Insert into [test] (Name,sex) VALUES (' Huang Zhiwen ', ' Men ')",
MyConnection)
Mycommand.executenonquery ()
la3.text= "New record inserted!"
' 3 Update data
mycommand = New SqlCommand ("UPDATE [test] SET name= ' Smith ' where Name= ' Li Ming '", MyConnection)
Mycommand.executenonquery ()
la4.text= "Record updated!"
' 4 Delete data
mycommand = New SqlCommand ("delete from [test] where name= ' Smith '", MyConnection)
Mycommand.executenonquery ()
la5.text= "Record deleted!"
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service