Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void btnsearch_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("select * from tbltransactioncustomer where RoomNum= '" + txtroomno.Text + "' and Status='Active' and Remark='CheckIn' ", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            txtadvancepayment.Enabled = false;
            if (dr.Read())
            {
                txtroomtype.Text = dr.GetValue(2).ToString();
                txtname.Text = dr.GetValue(3).ToString();
                txtage.Text = dr.GetValue(4).ToString();
                txtcheckindate.Text = dr.GetValue(9).ToString();
                txtadvancepayment.Text = dr.GetValue(13).ToString();
                
                txtcheckoutdate.Text = DateTime.Now.ToString ();
                lblperdaycharge.Text = dr.GetValue(14).ToString();
                // date calculation
                DateTime start = new DateTime();
                DateTime over = new DateTime();
                
                start = Convert .ToDateTime( txtcheckindate.Text);
                over =  Convert .ToDateTime(txtcheckoutdate.Text);
                TimeSpan datecalculation = over - start ;

                lblcountdays.Text = datecalculation.Days.ToString ();
                //----- date calculation end
  //------ Amount to be check   
  //*******************************  M geting error here ***********************************
// ******************************** can any one slove this  *********************************
        // here on multiplication [*] m getting error help me to solve this error please 
       // in vb.net this line of code works fine but in c# m getting error
     // lbldebitamount.Text = lblperdaycharge.Text * datecalculation.Days
    //operator * cannot be applied to operands of type 'string' and 'string' this is error  
               lbldebitamount.Text = lblperdaycharge.Text * lblcountdays .Text ;
            }
            con.Close();
        }
Posted
Updated 9-Mar-14 4:12am
v2
Comments
SanSkun 9-Mar-14 11:23am    
Hi,
May I know whats the error.

1 solution

You situation is similar to this:
C#
string perdaycharge = "12.35";
string countday = "2";
// error: Operator '*' cannot be applied to operands of type 'string' and 'string'
Decimal cost = perdaycharge * countday; // line 4

Line 4 will produce that error as it cannot multiply string and string, you have to parse the 2 strings to the respective number types before any arithmetic operation. Change line 4 as follows:
Decimal cost = Decimal.Parse(perdaycharge) * int.Parse(countday);

Apply this to your case.
 
Share this answer
 
v2
Comments
Tarun Jaiswal 9-Mar-14 15:54pm    
yes sir it work fine thanks .
Peter Leow 10-Mar-14 3:14am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900