error converting the varchar value 'id' to a column of data type int.

indyB

Member
Joined
Mar 13, 2003
Messages
15
Ive got a page that outputs a list of categories, each of which
links to a detail page which is to show the detail of the respective
category. That is Im passing a url variable. Im using the
category id to link to the detail page rather then the category
name to keep the url from being sloppy. My problem is that Im
getting this error when my detail page tries to read my url
variable. Is there a way I can control the data type to ensure
that this variable is properly passed and read? Thanks!

Heres the error message I get:

Error converting the varchar value id to a column of data type int.

Heres the code for the category page:
Code:
<wmx:SqlDataSourceControl id="SqlDataSourceControl1" runat="server" DeleteCommand="" ConnectionString="server=localhost; user id=sa; password=; Database=IAR" AutoGenerateUpdateCommand="False" SelectCommand="SELECT DISTINCT Category, CatID FROM [CommandFax]" UpdateCommand=""></wmx:SqlDataSourceControl>
            <wmx:MxDataGrid id="MxDataGrid1" runat="server" BorderStyle="None" BorderWidth="1px" CellPadding="3" BackColor="White" AllowPaging="False" DataMember="CommandFax" AutoGenerateFields="False" AllowSorting="True" BorderColor="#CCCCCC" DataSourceControlID="SqlDataSourceControl1">
            <PagerStyle horizontalalign="Center" forecolor="#000066" backcolor="White" mode="NumericPages"></PagerStyle>
            <FooterStyle forecolor="#000066" backcolor="White"></FooterStyle>
            <SelectedItemStyle font-bold="True" forecolor="White" backcolor="#669999"></SelectedItemStyle>
            <ItemStyle forecolor="#000066"></ItemStyle>
            <Fields>
                <wmx:HyperLinkField DataTextField="Category" SortExpression="Category" HeaderText="Category" DataNavigateurlField="catID" DataNavigateUrlFormatString="comFaxDetail.aspx?id={0}"></wmx:HyperLinkField>
            </Fields>
            <HeaderStyle font-bold="True" forecolor="White" backcolor="#006699"></HeaderStyle>
            </wmx:MxDataGrid>

And Heres the code for the detail page:
Code:
<wmx:SqlDataSourceControl id="SqlDataSourceControl1" runat="server" DeleteCommand="" ConnectionString="server=localhost; user id=sa; password=; Database=IAR" AutoGenerateUpdateCommand="False" SelectCommand="SELECT * FROM [CommandFax] WHERE CatID = id ORDER BY docNumber ASC" UpdateCommand=""></wmx:SqlDataSourceControl>
        <wmx:MxDataGrid id="MxDataGrid1" runat="server" BorderStyle="None" BorderWidth="1px" CellPadding="3" BackColor="White" AllowPaging="True" DataMember="CommandFax" AutoGenerateFields="False" AllowSorting="True" BorderColor="#CCCCCC" DataSourceControlID="SqlDataSourceControl1">
            <PagerStyle horizontalalign="Center" forecolor="#000066" backcolor="White" mode="NumericPages"></PagerStyle>
            <FooterStyle forecolor="#000066" backcolor="White"></FooterStyle>
            <SelectedItemStyle font-bold="True" forecolor="White" backcolor="#669999"></SelectedItemStyle>
            <ItemStyle forecolor="#000066"></ItemStyle>
            <Fields>
                <wmx:BoundField DataField="Category" SortExpression="Category" HeaderText="Category"></wmx:BoundField>
                <wmx:BoundField DataField="CatID" SortExpression="CatID" HeaderText="CatID"></wmx:BoundField>
                <wmx:BoundField DataField="docTitle" SortExpression="docTitle" HeaderText="docTitle"></wmx:BoundField>
                <wmx:BoundField DataField="docNumber" SortExpression="docNumber" HeaderText="docNumber"></wmx:BoundField>
                <wmx:BoundField DataField="pdfFileName" SortExpression="pdfFileName" HeaderText="pdfFileName"></wmx:BoundField>
                <wmx:BoundField DataField="id" SortExpression="id" HeaderText="id"></wmx:BoundField>
            </Fields>
            <HeaderStyle font-bold="True" forecolor="White" backcolor="#006699"></HeaderStyle>
        </wmx:MxDataGrid>
 
Last edited by a moderator:
Assign the value of the SQL statement in Page_Load.

Code:
SqlDataSourceControl1.SelectCommand = "SELECT... WHERE [CatID] = " & Request.QueryString("id") & " ORDER BY..."
 
Back
Top