我得到拋出了以下錯誤:指數在asp.net數組的邊界之外用vb
index was outside the bounds of the array
當使用此代碼:
con.Open()
qur = "select Username,password from registration where Username='" + TextBox1.Text + "'"
cmd = New SqlCommand(qur, con)
dr = cmd.ExecuteReader()
If dr.HasRows() Then
dr.Read()
Session("us1") = dr.GetValue(11).ToString()
Session("ps1") = dr.GetValue(12).ToString()
If Session("us1") = TextBox1.Text And Session("ps1") = TextBox2.Text Then
Response.Redirect("APP.aspx")
End If
End If
End Sub
可能有人請指出哪裏/爲什麼會出錯?
把斷點,看看dr有這些11和12項 你得到這個錯誤,因爲沒有什麼在11或可能是第12的位置。 – Rex
確保'dr'有13個項目。 –
請注意,您的代碼是廣泛開放的SQL注入 - 儘可能使用參數化查詢 –