我是新來的.net,當我運行該程序時,它報告錯誤「無法將類型爲System.Int32的對象強制轉換爲類型系統。字符串」System.Int32 cound不能轉換爲System.String的類型
進口System.Data 進口System.Data.SqlClient的 進口System.Data.Sql分部類_Default 繼承System.Web.UI.Page
Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
Dim constr As String
constr = ConfigurationManager.ConnectionStrings("libConstr").ConnectionString Dim conn As SqlConnection
conn = New SqlConnection(constr)
conn.Open()
Dim com As SqlCommand
com = New SqlCommand()
com.Connection = conn
com.CommandText = "select * from library"
Dim dr As SqlDataReader
dr = com.ExecuteReader()
Dim i As Integer
i = 0
Do While dr.Read()
If tbuser.Text = dr.GetString(i) Then //here report the error:無法將類型爲System.Int32的對象強制轉換爲類型System.String(System.Int32 cound not be cast to the type of System.String)
If tbid.Text = dr.GetString(i + 1) Then
Response.Redirect("library.aspx")
End If
i = i + 1
End If
Loop
End Sub
有什麼問題,你可以幫助我。 非常感謝。
但我認爲tbuser.Text是字符串類型。 – hon 2011-05-27 15:54:19
亂碼是中文電腦上的錯誤信息。 – CodesInChaos 2011-05-27 15:54:51
@hon然後你需要先讀取它作爲字符串,並調用'ToString()'的結果。 – CodesInChaos 2011-05-27 15:55:23