• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Parse error

I am getting an error: operator  "/" cannot be applied to operand of  type string and string; from

Calculate = int.Parse(drow["Retardation"].ToString()) * (Tx02.Text/DL.Text) statement...


What would cause that???
0
devlins
Asked:
devlins
  • 4
  • 3
  • 3
  • +3
1 Solution
 
rajaloysiousCommented:
You have to convert them to double

double d1 = Convert.ToDouble(Tx02.Text)/Convert.ToDouble(DL.Text);

Calculate = int.Parse(drow["Retardation"].ToString()) * d1 ;

cheers
0
 
PeteMcCommented:
the calculation you are doing you need to parse each item to an int first
Calculate=(int.Parse(drow["Retardation"].ToString()) *(int.Parse(Tx02.Text.ToString())/int.Parse(DL.Text.ToString())));
0
 
devlinsAuthor Commented:
Now it says cannot convert type int and double to datacolumn
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
devlinsAuthor Commented:
How can I eliminate the 'cannot convert type int and double to datacolumn' error????
0
 
vladimir_kalashnikovCommented:
you need to try:

Calculate = (int)(double.Parse(drow["Retardation"].ToString())) * (double.Parse(Tx02.Text)/double.Parse(DL.Text));
0
 
devlinsAuthor Commented:
Vlad it gives the same error: cannot convert  type 'double' to system.data.datacolumn...
0
 
PeteMcCommented:
what is Calculate declared as?
0
 
vladimir_kalashnikovCommented:
it should be an int
0
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
If Retardation contains an int the following should work:

Calculate = Convert.ToInt32((int)drow["Retardation"].Value) * (double.Parse(Tx02.Text)/double.Parse(DL.Text));

If it's a decimal or double replace the first cast with the correct type.
0
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
Whoops, missed a pair or braces.

Calculate = Convert.ToInt32(((int)drow["Retardation"].Value) * (double.Parse(Tx02.Text)/double.Parse(DL.Text)));
0
 
vladimir_kalashnikovCommented:
the thing about:

Calculate = Convert.ToInt32(((int)drow["Retardation"].Value) * (double.Parse(Tx02.Text)/double.Parse(DL.Text)));

is that using the Convert methods is much slower that either casting or using int.Parse.  That is why i would recommend:

Calculate = (int)( double.Parse(drow["Retardation"].ToString()) ) * ( double.Parse(Tx02.Text) / double.Parse(DL.Text) );

if this still causes errors, you could isolate the error like so:

string s1 = drow["Retardation"].ToString();

double d1 = double.Parse(s1);
double d2 = double.Parse(Tx02.Text);
double d3 = double.Parse(DL.Text);

int i1 = (int)(d1*d2/d3);

Calculate = i1;

that should allow you to find out exactly what is causing the error, if it continues.
0
 
dunglaCommented:
Calculate.DefaultValue;
0
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
A nice speed comparison can be found here: http://aspalliance.com/articleViewer.aspx?aId=80&pId=3
0
 
devlinsAuthor Commented:

I attached the datagrid code and the code behind to see if this is being done correctly..


The only problem is that it is not populating the Calculate column with the computed solution......          
or the defualt value............





<asp:datagrid id=DGrid runat="server" Width="896px" AllowSorting="True" PageSize="250" Height="431px" OnEditCommand="Edit_Click" OnCancelCommand="CancelIt" OnUpdateCommand="OnUpdate_Click" DataMember="Main_Waveplate_Inv" DataSource="<%# DataS %>" AutoGenerateColumns="False" BorderColor="#DEBA84" BorderStyle="None" CellSpacing="2" BorderWidth="1px" BackColor="#DEBA84" CellPadding="3" DataKeyField="Part_Key">
                                             <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
                                             <SelectedItemStyle Font-Bold="True" ForeColor="Silver" BackColor="#738A9C"></SelectedItemStyle>
                                             <EditItemStyle Font-Bold="True" BackColor="Gray"></EditItemStyle>
                                             <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
                                             <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
                                             <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#5283B5"></HeaderStyle>
                                             <Columns>
                                                  <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Reserve"></asp:EditCommandColumn>
                                                  <asp:BoundColumn DataField="Inventory_Status" SortExpression="Inventory_Status" HeaderText="Inventory_Status"></asp:BoundColumn>
                                                  <asp:BoundColumn DataField="Part_Key" SortExpression="Part_Key" ReadOnly="True" HeaderText="Part_Key"></asp:BoundColumn>
                                                  <asp:BoundColumn DataField="Diameter" SortExpression="Diameter" ReadOnly="True" HeaderText="Diameter"></asp:BoundColumn>
                                                  <asp:BoundColumn DataField="Retardation" SortExpression="Retardation" ReadOnly="True" HeaderText="Retardation"></asp:BoundColumn>
                                                  <asp:BoundColumn DataField="Retardation_Dec" SortExpression="Part_Key" ReadOnly="True" HeaderText="Retardation_Dec"></asp:BoundColumn>
                                                  <asp:BoundColumn DataField="Reserve_Customer" SortExpression="Reserve_Customer" HeaderText="Reserve_Customer"></asp:BoundColumn>
                                                  <asp:TemplateColumn SortExpression="Reserve_User" HeaderText="Reserve_User">
                                                       <ItemTemplate>
                                                            <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Reserve_User") %>' ID="Reserve_User"/>
                                                       </ItemTemplate>
                                                       <EditItemTemplate>
                                                            <asp:DropDownList runat="server" SelectedIndex='<%#GetSalesIndex(DataBinder.Eval(Container.DataItem, "Reserve_User").ToString()) %>' id="R_User">
                                                                 <asp:ListItem>ROBERTD</asp:ListItem>
                                                                 <asp:ListItem>EMA</asp:ListItem>
                                                                 <asp:ListItem>PHILD</asp:ListItem>
                                                                 <asp:ListItem>SYSADM</asp:ListItem>
                                                            </asp:DropDownList>
                                                       </EditItemTemplate>
                                                  </asp:TemplateColumn>
                                                  <asp:TemplateColumn SortExpression="Calculate" HeaderText="Calculate"></asp:TemplateColumn>
                                             </Columns>
                                             <PagerStyle NextPageText="NEXT" BorderColor="Gold" PrevPageText="PREVIOUS" HorizontalAlign="Right"
                                                  ForeColor="#5283B5" Position="TopAndBottom" BackColor="CornflowerBlue"></PagerStyle>
                                        </asp:datagrid></DIV

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Conn.Open();
                   
                    string sqlC = "(select top 200 * from Main_Waveplate_Inv where  ((Retardation between " + E0.Text + " and " + E.Text + ") or (Retardation between " + E.Text + " and " + E0.Text + ")) and Diameter = '" + D.SelectedItem.Text + "') order by Retardation desc" ;
                    Eq1.Text + " and Diameter = '" + Diameter.Text + "')";
                   
         
     


                    Waveplate.Retardation/(Tx02.Text *DL.Text)";

                    DataA = new System.Data.SqlClient.SqlDataAdapter(sqlC, Conn);
                    DataTable DTable = new DataTable();
               
                    Retardation)(@Eq1,@Eq2)",Conn) ;
               
                    double d3 = double.Parse(DL.Text);
               
                    DataRow IRow;
                   
                    IRow = DTable.NewRow();
               

DataColumn Calculate = new DataColumn();
                   
                    Calculate.DefaultValue=0;
DataS.Tables[0].Columns.Add(Calculate);

int i1 = (int)(d1*d2/d3);

                    foreach(DataRow dRow in DataS.Tables[0].Rows)
                    {
                    dRow["Calculted"]=(int)( double.Parse(IRow["Retardation"].ToString()) ) * ( double.Parse(Tx02.Text) / double.Parse(DL.Text) );
                   
                   
                   
                    }
     
//Calculate = i1.ToString();
                    DataA.Fill(DataS, "Main_Waveplate_Inv");
                    DGrid.DataSource = DataS;
                    DGrid.DataMember = "Main_Waveplate_Inv";
               
               
                   
                   

                   
                             
               

                   
                         DataS.Tables.Add();
                         DGrid.DataBind();
                         Conn.Close();
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now