简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM