Dim command As New SqlCommand("SELECT * From tblUserInfo WHERE Username='" & Trim(frmdashboard.ToolStripLabel4.Text) & "'", con)
Dim table As New DataTable()
Dim sqlAdapter As New SqlDataAdapter(command)
sqlAdapter.Fill(table)
Me.UserTypeTextBox.Text = table.Rows(0)(10).ToString()
Me.UsernameTextBox.Text = table.Rows(0)(9).ToString()
Me.Email_AddressTextBox.Text = table.Rows(0)(12).ToString()
Me.PositionTextBox.Text = table.Rows(0)(1).ToString()
Me.NameTextBox.Text = table.Rows(0)(2).ToString()
Me.AddressTextBox.Text = table.Rows(0)(3).ToString()
Me.Date_of_BirthDateTimePicker.Value = table.Rows(0)(4).ToString()
Me.AgeTextBox.Text = table.Rows(0)(5).ToString()
Me.SexComboBox.Text = table.Rows(0)(6).ToString()
Me.Telephone_NumberTextBox.Text = table.Rows(0)(7).ToString()
Me.Mobile_NumberTextBox.Text = table.Rows(0)(8).ToString()
Me.Security_Question_1TextBox.Text = table.Rows(0)(13).ToString()
Me.Security_Question_2TextBox.Text = table.Rows(0)(15).ToString()
Dim img() As Byte
img = table.Rows(0)(17)
Dim ms As New MemoryStream(img)
Me.PicturePictureBox.Image = Image.FromStream(ms)
这应检索特定人员的数据。我得到的错误是
System.IndexOutOfRangeException:在位置0没有行
您假设您的查询将返回至少一条记录,该记录可能/可能并非一直都为真。您应该首先检查您的表是否至少有一行,如下所示: