Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input string was not in a correct format. error

Status
Not open for further replies.

zma

Programmer
May 30, 2006
25
US
Trying to fill Detailsview1 based on the column idmain in Gridview1. The tables involved both have a field called demid (same as alias idmain) which is an integer value uniquely identifying each record in a demographic table. Other records in different tables associated with a particular demographic record have the same demid.

-----------I am getting this error before the gridview1 shows up-Exception Details: System.FormatException: Input string was not in a correct format. With the detailsview and sqldatasource commented out-it does not get an error message and runs ok up to there.

----------What am I doing wrong?

<asp:GridView runat="server" id="GridView1" AutoGenerateColumns="False" ShowHeader="False" AutoGenerateSelectButton="True" DataKeyNames="idmain">
<Columns>
<asp:boundfield DataField="idmain" Headertext="id"> </asp:boundfield>
<asp:boundfield DataField="cname" HeaderText="Child's Name"> </asp:boundfield>
<asp:boundfield DataField="cdob" HeaderText="Child's DOB"> </asp:boundfield>
<asp:boundfield DataField="srv" HeaderText="Service"> </asp:boundfield>
<asp:boundfield DataField="dfrom" HeaderText="dfrom"> </asp:boundfield>
</Columns>
</asp:GridView>
<asp:DetailsView runat="server" Width="125px" Height="50px" id="DetailsView1" DataSourceID="SqlDataSource1">
</asp:DetailsView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ %>" SelectCommand="SELECT [demID], [srv], [dfrom] FROM [tblvis] WHERE ([demID] = @demId)">
<SelectParameters>
<asp:controlparameter ControlID="GridView1" PropertyName="SelectedValue" DefaultValue="demid" Name="demID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

 
The problem here is this will be hard to debug because you are using the SqlDataSource control. I suggest you stop using them,and use stored procedures with parameters.

This error usually means you are trying to put a string or character value in to a numeric variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top