Saturday, March 31, 2012

There is no row at position 0.

I'm using the same page to add new records and update existing records, If there is now record for the client I get the "There is no row at position 0" message. Is there a way to prevent this when the page opens? Below is my code used in the page load event.

 SelectStatement ="SelectClientID,ClassYear,HouseName,CampusName,EducationMajor,GraduationDate FROM tblClients Where [ClientID]=" & _ ClientIDSentDim MyConnectionAs New SqlConnection(ConnectStr)Dim MyAdapterAs SqlDataAdapter =New SqlDataAdapter(MyCommand)Dim ClientDetailsDSAs DataSet =New DataSet MyConnection.ConnectionString = ConnectStr MyAdapter.SelectCommand =New SqlCommand(SelectStatement, MyConnection) MyCommandBuilder =New SqlCommandBuilder(MyAdapter) MyAdapter.Fill(ClientDetailsDS,"tblClients")Try'Fill Alumni Fields. Row = ClientDetailsDS.Tables("tblGivers").Rows(0) ClassYearText.Text = Row.Item("Classyear").ToString() HouseNameText.Text = Row.Item("HouseName").ToString() CampusNameText.Text = Row.Item("CampusName").ToString() EducationMajorText.Text = Row.Item("EducationMajor").ToString() BasicDatePickerGradDate.SelectedValue = Row.Item("GraduationDate").ToString() GraduationDateText.Text = Row.Item("GraduationDate").ToString()Catch exAs ExceptionDim strMessageAs String = ex.Message Response.Write(ex.Message)Finally End Try

Hi Jack

Change your code to check that ClientDetailsDS.Tables("tblGivers").Rows > 0 before then tryong to use the code within'Fill Alumni Fields

Looks like Rows.Count will return 0 and your then trying to set the text fields incorrectly using Row.

Cheers
Gregor


Perfect!

0 comments:

Post a Comment