Sub LoadCommandList()
End Sub
二
Asp
<%@ Import Namespace="System
<%@ Import NameSpace="System
<script laguage="VB" runat="server">
sub page_load(sender as Object
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ds as DataSet
myConnection = New SqlConnection( "server=localhost;database=Pubs;uid=ueytjdf;pwd=doekdf" )
myConnection
la
myCommand = New SqlCommand( "CREATE TABLE [test] ([id] [int] IDENTITY (
myCommand
la
myCommand = New SqlCommand( "Insert into [test] (name
myCommand
la
myCommand = New SqlCommand( "UPDATE [test] SET name=
myCommand
la
myCommand = New SqlCommand( "delete from [test] where name=
myCommand
la
myCommand = New SqlCommand( "select * from [test]"
MyDataGrid
MyDataGrid
end sub
</script>
<html>
<body>
<asp:label id="la
<asp:label id="la
<asp:label id="la
<asp:label id="la
<asp:label id="la
<ASP:DataGrid id="MyDataGrid" runat="server"
BorderColor="black"
BorderWidth="
GridLines="Both"
CellPadding="
CellSpacing="
Font
Font
HeaderStyle
AlternatingItemStyle
>
</asp:DataGrid>
</body>
</html>
ASP
<%@ Import Namespace="System
<%@ Import NameSpace="System
<script laguage="VB" runat="server">
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
sub page_load(sender as Object
dim dbname as string
dbname=server
myConnection = New OleDbConnection( "PROVIDER=Microsoft
myConnection
la
myCommand = New OleDbCommand( "Insert INTO Authors(Authors
myCommand
la
myCommand = New OleDbCommand( "UPDATE Authors SET Authors=
myCommand
la
myCommand = New OleDbCommand( "DELETE FROM Authors WHERE Authors =
myCommand
la
myCommand = New OleDbCommand( "select * FROM Authors"
MyDataGrid
MyDataGrid
end sub
</script>
<html>
<body>
<asp:label id="la
<asp:label id="la
<asp:label id="la
<asp:label id="la
<ASP:DataGrid id="MyDataGrid" runat="server"
BorderColor="black"
BorderWidth="
GridLines="Both"
CellPadding="
CellSpacing="
Font
Font
HeaderStyle
AlternatingItemStyle
>
</asp:DataGrid>
</body>
</html>
using System
using System
string strConnection="Provider=Microsoft
strConnection+=@"Data Source=C:BegASPNETNorthwind
OleDbConnection objConnection=new OleDbConnection(strConnection);
objConnection
objConnection
解釋:
連接Access數據庫需要導入額外的命名空間
strConnection這個變量裡存放的是連接數據庫所需要的連接字符串
"Provider=Microsoft
"Data Source=C:BegASPNETNorthwind
PS:
strConnection+="Data Source=";
strConnection+=MapPath("Northwind
這樣就可以省得你寫一大堆東西了!
"OleDbConnection objConnection=new OleDbConnection(strConnection);"這一句是利用定義好的連接字符串來建立了一個鏈接對象
"objConnection
using System
using System
string strConnection="user id=sa;password=;";
strConnection+="initial catalog=Northwind;Server=YourSQLServer;";
strConnection+="Connect Timeout=
SqlConnection objConnection=new SqlConnection(strConnection);
objConnection
objConnection
解釋:
連接SQL Server數據庫的機制與連接Access的機制沒有什麼太大的區別
首先
其次就是他的連接字符串了
"user id=sa":連接數據庫的驗證用戶名為sa
"password=":連接數據庫的驗證密碼為空
這裡注意
"initial catalog=Northwind":使用的數據源為"Northwind"這個數據庫
"Server=YourSQLServer":使用名為"YourSQLServer"的服務器
"Connect Timeout=
在這裡
using System
using System
//在窗體上添加一個按鈕
private void Button
{
string ConnectionString="Data Source=sky;user=system;password=manager;";//寫連接串
OracleConnection conn=new OracleConnection(ConnectionString);//創建一個新連接
try
{
conn
OracleCommand cmd=conn
cmd
OracleDataReader odr=cmd
while(odr
{
Response
}
odr
}
catch(Exception ee)
{
Response
}
finally
{
conn
}
}
using MySQLDriverCS;
// 建立數據庫連接
MySQLConnection DBConn;
DBConn = new MySQLConnection(new MySQLConnectionString("localhost"
DBConn
// 執行查詢語句
MySQLCommand DBComm;
DBComm = new MySQLCommand("select Host
// 讀取數據
MySQLDataReader DBReader = DBComm
// 顯示數據
try
{
while (DBReader
{
Console
}
}
finally
{
DBReader
DBConn
}
//關閉數據庫連接
DBConn
OleDbConnection
//打開數據庫連接
OleDbDataAdapter
//將得來的數據填入dataSet
DataGrid
//綁定數據
OleDbConnection
//關閉連接
//增加數據庫數據
在Web Form上新增對應字段數量個數的TextBox
this
(
OleDbInsertCommand
//打開連接
OleDbInsertCommand
//執行該SQL語句
OleDbInsertCommand
//關閉連接
(OleDb)
Provider=Sybase
From:http://tw.wingwit.com/Article/program/net/201311/14210.html