我正在尝试自动填写使用html和输入框创建的文本框。这就是我所拥有的:
Imports System.Object
Imports System.Web.UI.Control
Imports System.Web.UI.HtmlControls.HtmlControl
Imports System.Web.UI.HtmlControls.HtmlInputControl
Imports System.Web.UI.HtmlControls.HtmlInputText
Public Class Route
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("Username") IsNot Nothing Then
Label1.Text = "Welcome, " & Session("Username").ToString()
Else
Response.Redirect("~/Default.aspx")
End If
'filling the text box
Dim intCount As Integer = 0
Dim Hometown1 As String = ""
Dim State1 As String = ""
Dim sqlConn As New SqlConnection("Data Source=CISWEB\UMCISSQL2008;Initial Catalog=StudentGov;User ID=sa;Password=Password1")
Dim sqlCmd As New SqlCommand
Dim sqlTable As New DataTable
sqlCmd.CommandText = "SELECT * FROM RegisteredUsers WHERE UMaryEmail = " & Session("Username")
Dim Adapter As New Odbc.OdbcDataAdapter(sqlCmd.ToString, sqlConn.ToString)
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
Adapter.Fill(sqlTable)
If sqlTable.Rows.Count > 1 Then
For intCount = 0 To sqlTable.Rows.Count - 1
Hometown1 = Convert.ToString(sqlTable.Rows(intCount)("Hometown1"))
State1 = Convert.ToString(sqlTable.Rows(intCount)("State1"))
intCount += 1
Next
Else
intCount = 0
Hometown1 = Convert.ToString(sqlTable.Rows(intCount)("Hometown1"))
State1 = Convert.ToString(sqlTable.Rows(intCount)("State1"))
End If
sqlConn.Close()
Request.Form("hometown") = (Hometown1 & ", " & State1)
End Sub
End Class
问题是,每次用户使用正确的凭据登录时,我都会收到错误消息。它是:
[ArgumentException:初始化字符串的格式不符合从索引0开始的规范。]
此错误始终出现在适配器声明
旁边