Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I run windows application, display error.

There is no row at position 0.


VB
Dim str1 = TBSER.Text
Dim sql1 As String = "select * from EmpInfo where EmpName='" + str1 + "'"
adp = New SqlDataAdapter(sql1, cn)
ds.Clear()
adp.Fill(ds)
TBID.Text = ds.Tables("EmpInfo").Rows(inc).Item(0)
TBNAME.Text = ds.Tables("EmpInfo").Rows(inc).Item(1)
TBAD1.Text = ds.Tables("EmpInfo").Rows(inc).Item(2)
TBAD2.Text = ds.Tables("EmpInfo").Rows(inc).Item(3)
CBCITY.Text = ds.Tables("EmpInfo").Rows(inc).Item(4)
TBTEL1.Text = ds.Tables("EmpInfo").Rows(inc).Item(5)
TBTEL2.Text = ds.Tables("EmpInfo").Rows(inc).Item(6)
TBMOB.Text = ds.Tables("EmpInfo").Rows(inc).Item(7)
CBFAC.Text = ds.Tables("EmpInfo").Rows(inc).Item(8)
Posted
Updated 16-Feb-11 4:29am
v2
Comments
Ryan Zahra 16-Feb-11 10:26am    
Debug your program and add a watch to the dataset. check if there is a table in the dataset and also check if the table contains any rows.
Sergey Alexandrovich Kryukov 16-Feb-11 12:06pm    
Very bad error text and whole idea. You need to change your design and prevent it.
--SA

Looks to me like your query returned nothing. Try running the query in SQL Management Studio to confirm this. You can handle the case of having 0 rows by:

if(ds.Tables["EmpInfo"].Rows.Count == 0)
{
//your code here
}
 
Share this answer
 
Comments
Dylan Morley 16-Feb-11 10:41am    
+5, code defensively - avoids lots of issues!
Seems to be that whatever the value is in TextBox TBSER there is no record where EmpName is equal to that. Have a look into you DB.

Cheers!
 
Share this answer
 
You should avoid constructing your query string in the way that you are as it is vulnerable to SQL Injection attacks. You should learn to use Parameterized Queries and always use them so that it becomes second nature.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900