我是新来的.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