ASP.NET 連線 SQL SERVER

摘要:ASP.NET 連線 SQL SERVER

 web.config

<appSettings>
    <!--設定連線字串-->
    <add key="connectionString" value="Persist Security Info=True;User ID=your Account;Password=your Password;Initial Catalog=your DBName;Data Source=your IP"/>
  </appSettings>

 

Common.vb
 

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Security

Public Class Common
" -- connectionStringIn-- "

" --con2Sql-- "
END CLASS

 

 TEST.VB

 

Partial Class TEST
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
          
         Dim strSQL As String
         Dim aryFd As New ArrayList
         Dim aryValue As New ArrayList
         Dim aryTableName As New ArrayList
         Dim ds_data As New Data.DataSet  
         strSQL = " 你的SQL語法 "
         aryFd.Add("替換字串")
         aryValue.Add("替換值")
         aryTableName.Add("您回傳的TABLENAME")
         ds_data = con2Sql(Common.GetConnectionString, strSQL, aryFd, aryValue, aryTableName)
          

            Dim htmltb As New HtmlTable
            Dim htmltr As New HtmlTableRow
            Dim htmltd As New HtmlTableCell
            htmltb.Border = 1

            For Each value As Data.DataRow In ds_data.tables("您回傳的TABLENAME").rows
                htmltr = New HtmlTableRow
                For Each tdvalue As Data.DataColumn In ds_data.tables("您回傳的TABLENAME").Columns
                    htmltd = New HtmlTableCell
                    htmltd.InnerHtml = value(tdvalue.ColumnName)
                    htmltr.Controls.Add(htmltd)
                Next
                htmltb.Controls.Add(htmltr)
            Next

            Form.Controls.Add(htmltb)

        Catch ex As Exception

        End Try
    End Sub

End Class