i don't know if this is the right forum for this question but here goes. I have created a gridview to display a list of records retrieved by a SQL query. Everytime I run it, I get the following error:
Object must implement IConvertible.
I thought it might have to do with the data I'm passing in the session string from the previous page. Here is that code:
ProtectedSub cmdSubmit_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles cmdSubmit.ClickSession.Add("Shift", shShift.SelectedItem)
Session.Add("Type", shType.SelectedItem)Session.Add("SelDate", OccDate.SelectedDate)
Response.Redirect("SelectIncRep.aspx")
Here is the code that is supposed to execute and display the data on page_init:
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames="RID"DataSourceID="SqlDataSource1"Width="1215px"BorderStyle="Groove"BorderWidth="4px">
<Columns>
<asp:BoundFieldDataField="RID"HeaderText="Record ID:"InsertVisible="False"ReadOnly="True"
SortExpression="RID"/>
<asp:BoundFieldDataField="Date"HeaderText="Date:"SortExpression="Date"/>
<asp:BoundFieldDataField="Shift_ID"HeaderText="Shift:"SortExpression="Shift_ID"/>
<asp:BoundFieldDataField="Xref_ID"HeaderText="Type Of Occurence:"SortExpression="Xref_ID"/>
<asp:BoundFieldDataField="Notes"HeaderText="Notes:"SortExpression="Notes"/>
</Columns>
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:PerfDataConnectionString %>"
SelectCommand="SELECT [RID], [Notes], [Date], [Shift_ID], [Xref_ID] FROM [Safety_data] WHERE (([Shift_ID] = @.Shift_ID) AND ([Xref_ID] = @.Xref_ID) AND ([Date] = @.Date))">
<SelectParameters>
<asp:SessionParameterName="Shift_ID"SessionField="Shift_ID"Type="Int32"/>
<asp:SessionParameterName="Xref_ID"SessionField="Type"Type="Int32"/>
<asp:SessionParameterName="Date"SessionField="Date"Type="DateTime"/>
</SelectParameters>
</asp:SqlDataSource>
What could be causing the issue?
|||Session.Add("Shift", shShift.SelectedItem)
BezerkRogue:
Session.Add("Type", shType.SelectedItem)
Session.Add("SelDate", OccDate.SelectedDate).....
<asp:SessionParameterName="Shift_ID"SessionField="Shift_ID"Type="Int32"/>
<asp:SessionParameterName="Xref_ID"SessionField="Type"Type="Int32"/>
<asp:SessionParameterName="Date"SessionField="Date"Type="DateTime"/>
Thanks. I made that correction but still get the same error. I dumped my temporary internet files to make sure I wasn't loading cached data. Could there be anything else I might have missed?
|||Did you already googled this error?
I found some results that all pointed in the same direction, which seams to be the case here also. You omitted the select type, so maybe this is the solution?
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:PerfDataConnectionString %>"
SelectCommand="SELECT [RID], [Notes], [Date], [Shift_ID], [Xref_ID] FROM [Safety_data] WHERE (([Shift_ID] = @.Shift_ID) AND ([Xref_ID] = @.Xref_ID) AND ([Date] = @.Date))"SelectType="Text">
|||I added the selectcommandtype line in and still get the same error. The stack trace is chinese to me so I have no idea what the problem is.
Object must implement IConvertible.
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details:System.InvalidCastException: Object must implement IConvertible.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidCastException: Object must implement IConvertible.] System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +2514354 System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +264 System.Web.UI.WebControls.Parameter.get_ParameterValue() +66 System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +254 System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +276 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +754 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69 System.Web.UI.Control.EnsureChildControls() +87 System.Web.UI.Control.PreRenderRecursiveInternal() +41 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832
|||Ok, I found the variable that is being passed wrong and corrected it. I have verified that I am getting variables passed and have printed them on screen. I have also verified that I have records available for those variables, now I just get no data. Am I missing a binding somewhere?
<asp:gridviewrunat="server"ID="RecordView"AutoGenerateColumns="False"DataKeyNames="RID"DataSourceID="SqlDataSource1"Width="1134px"GridLines="Both"EnableViewState="true"Visible="true">
<Columns>
<asp:BoundFieldDataField="RID"HeaderText="RID"Visible="true"ReadOnly="True"
SortExpression="RID"/>
<asp:BoundFieldDataField="Notes"HeaderText="Notes"Visible="true"SortExpression="Notes"/>
</Columns>
</asp:gridview>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:PerfDataConnectionString %>"
SelectCommand="SELECT [RID], [Notes] FROM [Safety_data] WHERE (([Date] = @.Date) AND ([Shift_ID] = @.Shift_ID) AND ([Xref_ID] = @.Xref_ID))"SelectCommandType="Text">
<SelectParameters>
<asp:QueryStringParameterName="Date"QueryStringField="strSelDate"Type="DateTime"/>
<asp:QueryStringParameterName="Shift_ID"QueryStringField="strShiftPull"Type="Decimal"/>
<asp:QueryStringParameterName="Xref_ID"QueryStringField="strTypePull"Type="Decimal"/>
</SelectParameters>
</asp:SqlDataSource>