Dear Sir,
Table Employees has data as follows
sno----name
1------Eric
2------Boris
3------Bill
Whien I enter "B" in text5 and run following codes then it show error message as
IndexOutOfRangeException was unhandeled
There is no row at position 0I have two question
1) Why it does not select name begins with "B"
2) If it has no row then why it does not exit sub.
Please Help
str = "select sno,name from employees "
str &= "where Name Like '" & (TextBox5.Text) & "%'"
cmd2 = New SqlClient.SqlCommand(str, con)
da2 = New SqlClient.SqlDataAdapter(cmd2)
dt3 = New DataTable
da2.Fill(dt3)
Dim REC As Integer
If dt3.Rows.Count = 0 Then
Exit Sub
Else
For REC = 0 To dt3.Rows.Count - 1
REC = DataGridView1.Rows.Add()
DataGridView1.Rows(REC).Cells(0).Value = (IIf(IsDBNull(dt3.Rows(REC).Item("sno")), 0, dt3.Rows(REC).Item("sno")))
DataGridView1.Rows(REC).Cells(1).Value = (IIf(IsDBNull(dt3.Rows(REC).Item("Name")), "", dt3.Rows(REC).Item("Name")))
Next
End If