Question

I tried bind a label from result SqlDataSource.But I get this error

Cannot perform '=' operation on System.String and System.Int32

<asp:SqlDataSource ID="SqlDataSource1"  FilterExpression="DeviceID='{0}'"   
   runat="server" ConnectionString="<%$ ConnectionStrings:DBConn %>" 
   SelectCommand="SELECT devcocom_admin.SensorDataPackage.a_TankLevel1, 
    devcocom_admin.SensorDataPackage.a_TankLevel2,devcocom_admin.DeviceID bla bla 
    bla Where bla bla ">

         <FilterParameters>


       <asp:ControlParameter Name="DeviceID" ControlID="lblDeviceIDText" 
        PropertyName="Text" />
       </FilterParameters>

         </asp:SqlDataSource>


 private void GetData()
    {
        DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        DataRowView drv =dv[0];

        lblTank1.Text = drv["a_TankLevel1"].ToString();
        lblTank2.Text = drv["a_TankLevel2"].ToString();
    }  


    protected void Page_Load(object sender, EventArgs e)
    {

      lblDeviceIDText.Text = this.m_Dealer.DeviceID.ToString();

       // e.g lblDeviceIDText.Text=12345 can display on page 

      GetData();           
   }

I get error at this line

DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);

Cannot perform '=' operation on System.String and System.Int32

Was it helpful?

Solution

Add DbType="Int32" to the ControlParameter. Here is the property link, and the enum link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top