初学VB.NET连接SQL数据库!

类别:.NET开发 点击:0 评论:0 推荐:
<%@ Page Language="VB" Debug="true" trace="true" %>
<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="System.data.SQLClient" %>
<script language="VB" runat="server">
Sub Page_Load(sender as object, E as eventargs)
    Dim ds as DataSet
    Dim MyConnection as SQLConnection
 Dim MyAdpt as SQLDataAdapter
 MyConnection =New SQLConnection("server='localhost';UID=sa;PWD=wenasen.com; database=credit_sql")
 MyAdpt = New SQLDataAdapter("select * from admin",MyConnection)
 ds= new DataSet()
 MyAdpt.Fill(ds,"admin")
 dgA.DataSource=ds.tables("admin").defaultView
 dgA.DataBind()
 end sub 
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>显示SQL数据库</title>
</head>
<body>
<form id="form1" runat="server">
<asp:datagrid id="dgA" runat="server" AllowPaging="true"  Width="100%" CellPadding="1" EditItemStyle-BackColor=""
 HeaderStyle-BackColor="#00CCCC"  border="1" AlternatingItemStyle-BackColor="#CCCCCC"
 ></asp:datagrid>
</form>
</body>
</html>

本文地址:http://com.8s8s.com/it/it41513.htm