ASP.Net/Asp Control/Connection MetaData — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:30, 26 мая 2010

Get database, server version and data source

<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>
<html>
  <body>
    <h4>First Example: Listing data from the Employees table</h4>
    <asp:DataGrid id="dgNameList"
                  runat="server"
                  Gridlines="None"
                  BackColor="LightBlue"
                  CellPadding="5"
                  CellSpacing="5"
                  BorderWidth="2"
                  BorderColor="Black"
                  ToolTip="Includes only those employees who are at HQ" />
  <body>
</html>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
"  Dim strConnection As String = "server=(local)\NetSDK; database=Northwind; " & _
 "                               "integrated security=true"
   Dim strConnection As String = "Data Source=whsql-v08.prod.mesa1.secureserver.net;Initial Catalog=DB_49907;User ID=nfexuser;Password="password";"
                                
  Dim objConnection As New SqlConnection(strConnection)
  Dim strSQL As String = "SELECT FirstName, LastName " & _
                         "FROM Employee;"
  Dim objCommand As New SqlCommand(strSQL, objConnection)
  objConnection.Open()
  Response.Write("ServerVersion: " & objConnection.ServerVersion & _
                 vbCRLF & "Datasource: " & objConnection.DataSource & _
                 vbCRLF & "Database: " & objConnection.Database)
  dgNameList.DataSource = objCommand.ExecuteReader()
  dgNameList.DataBind()
  objConnection.Close()
End Sub
</script>