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

5.1k views Asked by At

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

1

There are 1 answers

5
Mike Perrenoud On BEST ANSWER

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