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

80酷酷网    80kuku.com

  初学|数据|数据库<% 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>

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: