<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataSetCommand '同数据库进行连接,采用sql server数据库
MyConnection = New SQLConnection("server='sun';uid=sa;pwd=jerrysun;database=cheshi")
'执行SQL操作
MyCommand = New SQLDataSetCommand("select * from mvip",MyConnection)
DS = New DataSet()
MyCommand.FillDataSet(ds, "cheshi")
MyDataGrid.DataSource=ds.Tables("cheshi").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<center>
<body>
<h3><font face="Verdana">Page_load数据库连接</font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="600"
BackColor="white"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
MaintainState="false"
/>
<body>
</center>
</html>这个每次执行的时候总是说我SQLConnection,SQLDataSetCommand没有定义。
请各位大虾帮个忙看一下
<%@ Import Namespace="System.Data.SQL" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataSetCommand '同数据库进行连接,采用sql server数据库
MyConnection = New SQLConnection("server='sun';uid=sa;pwd=jerrysun;database=cheshi")
'执行SQL操作
MyCommand = New SQLDataSetCommand("select * from mvip",MyConnection)
DS = New DataSet()
MyCommand.FillDataSet(ds, "cheshi")
MyDataGrid.DataSource=ds.Tables("cheshi").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<center>
<body>
<h3><font face="Verdana">Page_load数据库连接</font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="600"
BackColor="white"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
MaintainState="false"
/>
<body>
</center>
</html>这个每次执行的时候总是说我SQLConnection,SQLDataSetCommand没有定义。
请各位大虾帮个忙看一下
是不是用错对象了?
SqlCommand或者SqlDataAdapter吧?
Dim MyConnection As SQLConnection strConnection = "data source=sun"
strConnection &= ";initial catalog=cheshi"
strConnection &= ";user id=sa"
strConnection &= ";password=jerrysun"
_MyConnection = New SqlConnection(strConnection)
Dim MyConnection As SQLConnection strConnection = "data source=sun"
strConnection &= ";initial catalog=cheshi"
strConnection &= ";user id=sa"
strConnection &= ";password=jerrysun"
MyConnection = New SqlConnection(strConnection)
' 打开连接
MyConnection.Open'只有打开后才能执行'关闭连接
MyConnection.Close()
你所说的
dim strConnection as String
Dim MyConnection As SQLConnection strConnection = "data source=sun"
strConnection &= ";initial catalog=cheshi"
strConnection &= ";user id=sa"
strConnection &= ";password=jerrysun"
MyConnection = New SqlConnection(strConnection)
其实跟我的里面的这一段是一样的
'同数据库进行连接,采用sql server数据库
MyConnection = New SQLConnection("server=sun;uid=sa;pwd=jerrysun;database=cheshi")
是一样的,只是少了一个打开MyConnection.Open
MyConnection.Close()