Solved

There is no row at position 0

Posted on 2003-12-01
23
5,457 Views
Last Modified: 2011-09-20
Hello experts!

I've been playing around with this display page for about an hour now and I'm stuck.  My boss is bugging me to see if I'm finished yet...I use a different page to pass a Deal# to this page.  It just displays fields relative to that deal number.  For some reason I can't get it to work though.

Here's the error:

System.IndexOutOfRangeException: There is no row at position 0.

Source Error:


Line 22:         End If
Line 23:         GetDealNo(DealNoSent_Int)
Line 24:         Row = DealInfo.Tables("odsc_finance").Rows(0)
Line 25:         CusNameText.Text = Row.Item("[Customer Last Name]")
Line 26:         DateText.Text = Row.Item("[Deal Date]")
 
Here is the code:

<%@ Page Explicit="true" Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

    Dim ConnectString, SelectStatement As String
    Dim Connect As SqlConnection = New SqlConnection
    Dim Adapter As SqlDataAdapter = New SqlDataAdapter
    Dim DealInfo As DataSet = New DataSet
    Dim Row As DataRow
    Dim DealNoSent As string
    Dim DealNoSent_Int As Int32

    Sub Page_Load(Sender As Object, E As EventArgs)
    Me.Button1.Attributes.Add("OnClick", "window.close()")
    If Not IsPostBack Then
        DealNoSent = Left(Request.QueryString("Reference#"),5)
        if (IsNumeric(DealNoSent)) Then
        DealNoSent_Int = Convert.ToInt32(DealNoSent)
        else
        DealNoSent_Int = 0
        End If
        GetDealNo(DealNoSent_Int)
        Row = DealInfo.Tables("odsc_finance").Rows(0)
        CusNameText.Text = Row.Item("[Customer Last Name]")
        DateText.Text = Row.Item("[Deal Date]")
        DMNAMEText.Text = Row.Item("[Desk Manager Name]")
        StatText.Text = Row.Item("Status")
        GrosText.Text = Row.Item("[Gross Payable]")
        HoldText.Text = Row.Item("Holdback")
        BackText.Text = Row.Item("[Finance Res]")
        DealText.Text = Row.Item("Deal#")
        SalesM1Text.Text = Row.Item("[Sales man1 Name]")
        SalesM2Text.Text = Row.Item("[Sales man2 Name]")
        MdlText.Text = Row.Item("Model") &""
        StkText.Text = Row.Item("Stock#")
        NUOText.Text = Row.Item("[New/Used]")
        CarlineText.Text = Row.Item("Make")
        YRText.Text = Row.Item("YEAR")
        CityText.Text = Row.Item("[Customer City]")
        StText.Text = Row.Item("[Customer State]")
        ZipText.Text = Row.Item("[Customer ZIP]")
        PhoneText.Text = Row.Item("[Customer Res Phone]")
        CashText.Text = Row.Item("[CS_Cash.Down]")
        TRModelText.Text = Row.Item("[Trade 1 Model Desc]") &""
        TradeText.Text = Row.Item("[Trade 1 ACV]") &""
        BankText.Text = Row.Item("[Bank Name]") &""
    End If
    End Sub

    Sub GetDealNo(DealNoSent As integer)
        SelectStatement = "Select * From odsc_finance Where Deal# = '" & DealNoSent & "'"
    ConnectString = "server=gwpf-web01;uid=sa;PWD=bigdellsql1;database=gwpf;"
    Connect.ConnectionString = ConnectString
    Adapter.SelectCommand = new SqlCommand(SelectStatement, Connect)
    Adapter.Fill(DealInfo,"odsc_finance")
    End Sub

</script>
<html>
<head>
    <title>Deal Information</title>
</head>
<body vlink="black" bgcolor="#94d6e7" onload="window.resizeTo(550, 800)">
    <form runat="server">
        <asp:Label id="header" runat="server" font-name="arial" font-size="22" font-bold="true" text="Deal Info"></asp:Label>
        <p>
            Here is the deal information you requested:
        </p>
        <table style="BORDER-COLLAPSE: collapse" cellspacing="1" width="100%" border="1">
            <tbody>
                <tr>
                    <td width="100%">
                        <b><font color="white" size="6">Customer Info</font></b></td>
                </tr>
                <tr>
                    <td>
                        <b>Customer Name:
                        <asp:textbox id="CusNameText" runat="server" columns="10" readonly="true"></asp:textbox>
                        </b></td>
                </tr>
                <tr>
                    <td>
                        <b>
                        &nbsp;&nbsp; City:
                        <asp:textbox id="CityText" runat="server" columns="15" readonly="true"></asp:textbox>
                        &nbsp;&nbsp; State:
                        <asp:textbox id="StText" runat="server" columns="5" readonly="true"></asp:textbox>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Zip:
                        <asp:textbox id="ZipText" runat="server" columns="5" readonly="true"></asp:textbox>
                        &nbsp;&nbsp;&nbsp;&nbsp; Phone #:
                        <asp:textbox id="PhoneText" runat="server" columns="15" readonly="true"></asp:textbox>
                        &nbsp;&nbsp; </b></td>
                </tr>
                <tr>
                    <td>
                        <b><font color="white" size="6">Vehicle Info</font></b></td>
                </tr>
                <tr>
                    <td>
                        <b>Model:
                        <asp:textbox id="MdlText" runat="server" columns="10" readonly="true"></asp:textbox>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Stock #:
                        <asp:textbox id="StkText" runat="server" columns="10" readonly="true"></asp:textbox>
                        New/Used:
                        <asp:textbox id="NUOText" runat="server" columns="3" readonly="true"></asp:textbox>
                        Carline:
                        <asp:textbox id="CarlineText" runat="server" columns="15" readonly="true"></asp:textbox>
                        Year:
                        <asp:textbox id="YRText" runat="server" columns="3" readonly="true"></asp:textbox>
                        </b></td>
                </tr>
                <tr>
                    <td>
                        <b><font color="white" size="6">Trade Info</font></b></td>
                </tr>
                <tr>
                    <td>
                        <b>Trade Model:
                        <asp:textbox id="TRModelText" runat="server" columns="10" readonly="true"></asp:textbox>
                        Trade:
                        <asp:textbox id="TradeText" runat="server" columns="10" readonly="true"></asp:textbox>
                        </b></td>
                </tr>
                <tr>
                    <td>
                        <b><font color="white" size="6">Deal Info</font></b></td>
                </tr>
                <tr>
                    <td>
                        <b>Deal #:
                        <asp:textbox id="DealText" runat="server" columns="3" readonly="true"></asp:textbox>
                        Deal Date:
                        <asp:textbox id="DateText" runat="server" columns="4" readonly="true"></asp:textbox>
                        Desk Mgr:
                        <asp:textbox id="DMNameText" runat="server" columns="18" readonly="true"></asp:textbox>
                        Salesman: 1:<asp:textbox id="SalesM1Text" runat="server" columns="15" readonly="true"></asp:textbox>
                        2:<asp:textbox id="SalesM2Text" runat="server" columns="15" readonly="true"></asp:textbox>
                        Status:
                        <asp:textbox id="STATText" runat="server" columns="5" readonly="true"></asp:textbox>
                        Front Gross:
                        <asp:textbox id="GrosText" runat="server" columns="6" readonly="true"></asp:textbox>
                        Holdback:
                        <asp:textbox id="HoldText" runat="server" columns="5" readonly="true"></asp:textbox>
                        Back Gross:
                        <asp:textbox id="BackText" runat="server" columns="10" readonly="true"></asp:textbox>
                        Cash Down:
                        <asp:textbox id="CashText" runat="server" columns="10" readonly="true"></asp:textbox>
                        Banke Name:
                        <asp:textbox id="BankText" runat="server" columns="25" readonly="true"></asp:textbox>
                        </b></td>
                </tr>
                <tr>
                </tr>
            </tbody>
        </table>
        <center>
            <asp:LinkButton id="Button1" runat="server" font-name="Arial" font-size="12 pt" font-bold="true">
[ Close ]</asp:LinkButton>
        </center>
    </form>
</body>
</html>

This is probably something stupid I've overlooked.  Help!
0
Comment
Question by:jay-are
  • 9
  • 6
  • 4
  • +2
23 Comments
 
LVL 4

Expert Comment

by:c_swanky
ID: 9853856

try changing

Row = DealInfo.Tables("odsc_finance").Rows(0)

To

Row = DealInfo.Tables("odsc_finance").Rows(DealNoSent_Int)
0
 
LVL 4

Expert Comment

by:ainapure
ID: 9853859
have u tried to do response.write("dealnosent"). Make sure you are receiving the values that is passed by another page. Before you execute the sql string, do a response.write to see the query structure.

if you believe that all the values are being sent the way they should be, then i will have to take another in depth shot at the code. But my initial doubt in on the Left() function you are using soon after you collect the values from the querystring.


-amit
0
 
LVL 4

Expert Comment

by:c_swanky
ID: 9853869
no.. stop.. don't do what I just said...!
0
 
LVL 4

Expert Comment

by:c_swanky
ID: 9853928
ainapure makes a good point, but it looks like you set the DealNoSent_Int to 0 if the passed value is not numeric. Which means that in your sub routine "GetDealNo(DealNoSent_Int)" you should check if your query returns any values before going to the following piece of code..


      Row = DealInfo.Tables("odsc_finance").Rows(0)
        CusNameText.Text = Row.Item("[Customer Last Name]")
        DateText.Text = Row.Item("[Deal Date]")
        DMNAMEText.Text = Row.Item("[Desk Manager Name]")
        StatText.Text = Row.Item("Status")
        GrosText.Text = Row.Item("[Gross Payable]")
        HoldText.Text = Row.Item("Holdback")
        BackText.Text = Row.Item("[Finance Res]")
        DealText.Text = Row.Item("Deal#")
        SalesM1Text.Text = Row.Item("[Sales man1 Name]")
        SalesM2Text.Text = Row.Item("[Sales man2 Name]")
        MdlText.Text = Row.Item("Model") &""
        StkText.Text = Row.Item("Stock#")
        NUOText.Text = Row.Item("[New/Used]")
        CarlineText.Text = Row.Item("Make")
        YRText.Text = Row.Item("YEAR")
        CityText.Text = Row.Item("[Customer City]")
        StText.Text = Row.Item("[Customer State]")
        ZipText.Text = Row.Item("[Customer ZIP]")
        PhoneText.Text = Row.Item("[Customer Res Phone]")
        CashText.Text = Row.Item("[CS_Cash.Down]")
        TRModelText.Text = Row.Item("[Trade 1 Model Desc]") &""
        TradeText.Text = Row.Item("[Trade 1 ACV]") &""
        BankText.Text = Row.Item("[Bank Name]") &""

0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9855126
jay-are,
you should try like this :

If DealInfo.Tables("odsc_finance").Rows.Count > 0 Then
       Row = DealInfo.Tables("odsc_finance").Rows(0)

       CusNameText.Text = Row.Item("[Customer Last Name]").toString()
       DateText.Text = Row.Item("[Deal Date]").toString()
       DMNAMEText.Text = Row.Item("[Desk Manager Name]").toString()
       StatText.Text = Row.Item("Status").toString()
       GrosText.Text = Row.Item("[Gross Payable]").toString()
       HoldText.Text = Row.Item("Holdback").toString()
       BackText.Text = Row.Item("[Finance Res]").toString()
       DealText.Text = Row.Item("Deal#").toString()
       SalesM1Text.Text = Row.Item("[Sales man1 Name]").toString()
       SalesM2Text.Text = Row.Item("[Sales man2 Name]").toString()
       MdlText.Text = Row.Item("Model") .toString()
       StkText.Text = Row.Item("Stock#").toString()
       NUOText.Text = Row.Item("[New/Used]").toString()
       CarlineText.Text = Row.Item("Make").toString()
       YRText.Text = Row.Item("YEAR").toString()
       CityText.Text = Row.Item("[Customer City]").toString()
       StText.Text = Row.Item("[Customer State]").toString()
       ZipText.Text = Row.Item("[Customer ZIP]").toString()
       PhoneText.Text = Row.Item("[Customer Res Phone]").toString()
       CashText.Text = Row.Item("[CS_Cash.Down]").toString()
       TRModelText.Text = Row.Item("[Trade 1 Model Desc]").toString()
       TradeText.Text = Row.Item("[Trade 1 ACV]").toString()
       BankText.Text = Row.Item("[Bank Name]").toString()
End If

-You also can use toString() instead of "". Always use Rows.Count to detect current total rows returned.This work as well for me.

Regards
x_com
0
 
LVL 3

Expert Comment

by:vijay7248
ID: 9856190
Hi,
I think the problem is with your datatype.

    Sub GetDealNo(DealNoSent As integer)
        SelectStatement = "Select * From odsc_finance Where Deal# = '" & DealNoSent & "'"
    ConnectString = "server=gwpf-web01;uid=sa;PWD=bigdellsql1;database=gwpf;"
    Connect.ConnectionString = ConnectString
    Adapter.SelectCommand = new SqlCommand(SelectStatement, Connect)
    Adapter.Fill(DealInfo,"odsc_finance")
    End Sub

What is the datatype of ur column Deal#??
    If it is an integer, then change ur query to the foll....
                  SelectStatement = "Select * From odsc_finance Where Deal# = " & DealNoSent
                  'The single quote is not needed for integer columns
    If Deal# is varchar then change ur query to the foll...
                  SelectStatement = "Select * From odsc_finance Where Deal# = '" & cstr(DealNoSent) & "'"
                  'since DealNoSent is integer change it to string
Moreover pls note that, if u have not, u r using a varible "DealNoSent"  as a "string globally" and as an "integer" inside the subroutine.

FYI, you will be able to access only the integer variable "DealNoSent" inside GetDealNo and not the global  string var "DealNoSent".To avoid much fuss any more pls change the var name of any one.


Hope this helps,
Vijay.
0
 
LVL 3

Expert Comment

by:vijay7248
ID: 9856208
If still there is a problem..
    Pls give
            response.write of the query
    and also after printing the query, give..
            response.write( typename(DealNoSent))  
        This will give the datatype of the of the variable u use to build ur query...


Hope this helps...  :)
Vijay
0
 

Author Comment

by:jay-are
ID: 9858409
Thanks for the quick responses.  Sorry its taken me so long to respond!  I've been trying all these solutions.  X_com:  I changed my code to match yours and it load the page without an error but all the textboxes are now blank.

I changed my select statement also Vijay and its still showing blank data.

I add in the response.write after the GetDealNo(DealNoSent_Int) and it returns a 0.  I also added it in after the select statement and it returns a 0.

??
The Deal# is a varchar.
0
 
LVL 4

Expert Comment

by:c_swanky
ID: 9860787
When you're testing, what does your url look like?    http://your-site.com/page-name.asp?Reference#=474837498393

1) Add a response.write after this:
DealNoSent = Left(Request.QueryString("Reference#"),5)
Response.write("DealNoSent=[" & DealNoSent &"]")

2) What's that value?


3) If "DealNoSent" is NOT numeric then you are setting it to zero.

      if (IsNumeric(DealNoSent)) Then
           DealNoSent_Int = Convert.ToInt32(DealNoSent)
      else
          DealNoSent_Int = 0
      End If

0
 

Author Comment

by:jay-are
ID: 9861017
http://gwpf-web01/aspx/new/dealno.aspx?Reference#=65061

that's the url

The response write returns this at the top of the window:

DealNoSent=[]

The reference# that gets passed to this page is a varchar.  The Deal# that is pulled in this page is a varchar.  Do I need to convert it to an integer?  Somone else helped me with that part for a previous page and I just carried it over thinking I still needed it.
0
 
LVL 4

Accepted Solution

by:
c_swanky earned 500 total points
ID: 9861289
Ok if that is blank then you are not getting the Ref # at all and that's why none of this working...

DealNoSent = Left(Request.QueryString("Reference#"),5)

Looks like the "#" is causing the problem

CHANGE THIS

DealNoSent = Left(Request.QueryString("Reference#"),5)

TO

DealNoSent = Left(Request.QueryString("Reference"),5)


AND YOUR URL TO THIS:

http://gwpf-web01/aspx/new/dealno.aspx?Reference=65061


try it now


0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 4

Expert Comment

by:c_swanky
ID: 9861339
Will there ever be a time that the Deal Number is longer than 5?  Because the way you have it now (using the Left function) if you pass a number like this  "12345678"   you will only get   "12345" passed into your code.
0
 

Author Comment

by:jay-are
ID: 9861598
c_swanky....IT WORKED!

I don't know why that worked but it did.  Please explain why that worked?  The field name is Reference# not Reference.  

The deal number is always five numbers and IF there is an adjustment on the deal then it gets changed to 12345A then 12345B and so on.

So the finance table only has the 5 digit numbers in it.  If there's an adjustment the old number just gets overwritten.  The schedule table on the other hand just adds a letter to the end of the deal number.  That's why I have to trim off that last letter.

0
 
LVL 4

Expert Comment

by:c_swanky
ID: 9861708

Great!

It was because you had the symbol "#" in the url and as a result it was causing a problem with the request.querystring not being able to pull the ID.

Make sure to change the code in the page that generates the url string so the symbol "#" is not there.

When in doubt always check the values being passed into your page. I like to use the following with hard-brackets "[" around the value just incase there are any spaces, etc...

Response.write("Your-Variable=[" & sSomeString &"]")

 
0
 

Author Comment

by:jay-are
ID: 9861718
Thank you!  

I realize that the previous page I was using that mirrored this one had ControlNo instead of Reference#...makes sense!

0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9863531
jay-are,
Ýour online time is different with me. But, i'm glad to see you got the solutions from c_swanky.
Nice job c_swanky. Actually, you need to split the points to vijay7248 too because he spotted out one of your problems too.

Regards
x_com
0
 
LVL 3

Expert Comment

by:vijay7248
ID: 9864340
@x_com
Thanks for the support.
@jay-are
If u think that my postings helped you then u can award me points.If not pls ignore this comment

-Vijay

0
 
LVL 4

Expert Comment

by:c_swanky
ID: 9864693
@jay-are - just say the word and I'll post a question for @vijay7248 for two fithy...(250 pts) so he gets credit too.  

 

0
 

Author Comment

by:jay-are
ID: 9866669
Vijay:  Sorry!  I was so excited that it was working that I forgot about you!
These are for you:  http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20815134.html


X_com: " -You also can use toString() instead of "". Always use Rows.Count to detect current total rows returned.This work as well for me."  -very helpful
thank you!
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20815138.html

I'm sure I'll be back soon!


0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9871832
@jay-are
Thanks :-)

@c_swanky,
Wow, you actually can ask admin to handle your request in CS area.:-)

@vijay7248,
As long your solutions work, should be award with expert's point. The main things is we can help asker to solve the problems and increase our knowledge in the same times. This TA need a lot of experts. Nice job! :-)

Regards
x_com
0
 
LVL 3

Expert Comment

by:vijay7248
ID: 9872319
Wow that's great .
thanks a lot jay-are


@x_com
Yeah u r right.
I've been actively into this site for barely a month now.But I enjoy the healthy competition and the friendly atmosphere here.

@swanky
Thats a nice job swanky and u deserve a 500 for that.

U guys make this site great.
0
 
LVL 4

Expert Comment

by:c_swanky
ID: 9872663

@vijay7248
Thanks!    Looks like jay-are took care of you on the points for this question.   So I guess we both made out pretty well!






0
 

Author Comment

by:jay-are
ID: 9874628
Thanks a lot for your help fellas.  You certainly make life on noobs like me much easier.  The project is coming along nicely and growing into a monster!

Appreciate all your help and look forward to asking more questions!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now