以下是我在aspx內寫的mysql連結 ..
請問 New MySqlConnection 要怎麼可以直接的把web.config,內的連結引用進來 ..
讓New MySqlConnection直接去抓web.config的add.name的值
web.config
<connectionStrings>
<add name="ConnectionString" connectionString="Dsn=CIM;uid=root;pwd=1234" providerName="System.Data.Odbc"/>
</connectionStrings>
aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myConn As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As Data.DataSet
Dim m_txt As String
m_txt = TextBox1.Text
myConn = New MySqlConnection("server=server-sc1web;user id=root;password=1234;database=cim")
myConn.Open()
Dim strSql = "select userid,username from user where userid ='" & m_txt & "'"
If m_txt <= "" Then
Label1.Text = "NO SQL"
MsgBox("123")
Else
MsgBox("456")
Label1.Text = strSql
End If
myDataAdapter = New MySqlDataAdapter(strSql, myConn)
myDataSet = New Data.DataSet()
myDataAdapter.Fill(myDataSet, "a1")
GridView1.DataSource = myDataSet.Tables("a1").DefaultView
GridView1.DataBind()
myConn.Close()
End Sub
煩請先進指導 ... 謝謝
<pre class="c" name="code">
Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim dbType As String = ConfigurationManager.ConnectionStrings("ConnectionString").ProviderName
使用上ok了 ,超感謝你的
想再請教個問題 , GridView1做分頁時第二頁後就無資料是那理忘了處理到了嗎?
小弟有在,以下加入DataBind ...但還是無解...不知大大您有解嗎...謝謝你
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
'GridView1.PageIndex = e.NewPageIndex
'GridView1.DataBind()