Solved

if statement c#

Posted on 2013-12-26
8
258 Views
Last Modified: 2014-01-28
I have a reader but i am converting to c# from vb. what is the equivalent of.

 while (myReader.Read())
                        {
                            if (myReader(1) < 10)  << error here
                            {
                                Other = myReader.GetInt32(1);
                            }
0
Comment
Question by:sevensnake77
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:13Shadow
Comment Utility
The code you posted is C#. Are you asking for the vb equivalent?
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
Yes
 Dim cIdx As Integer = -1
        Dim Other As Integer
        Dim NotProvided As Integer

  Do While sqlDR.Read
            If sqlDR("ttt") < 10 Then
                Other += sqlDR("ttt") 
            ElseIf sqlDR("ttt")  = "" Then
                NotProvided += sqlDR("ttt") 
            Else
                cIdx += 1
                ReDim Preserve yValues(cIdx)
                ReDim Preserve xValues(cIdx)
                xValues(cIdx) = sqlDR("ttt") 
                yValues(cIdx) = sqlDR("AAA") 
            End If
        Loop

        If Other > 0 Then
            cIdx += 1
            ReDim Preserve yValues(cIdx)
            ReDim Preserve xValues(cIdx)
            xValues(cIdx) = "Other"
            yValues(cIdx) = Other
        End If

        If NotProvided >= 0 Or NotProvided = "0" Then
            cIdx += 1
            ReDim Preserve yValues(cIdx)
            ReDim Preserve xValues(cIdx)
            xValues(cIdx) = "Not Provided"
            yValues(cIdx) = NotProvided
        End If

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
Even the c# code comes out as error when I use the less than sign with an integer.
0
 
LVL 3

Assisted Solution

by:13Shadow
13Shadow earned 500 total points
Comment Utility
What are you trying to do in this statement?  If sqlDR("ttt") < 10 Then
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Accepted Solution

by:
13Shadow earned 500 total points
Comment Utility
If you are trying to compare the value to 10 you need to convert it to integer first since the reader returns string values:
If CType(sqlDR("ttt"), Integer) < 10 Then
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
  List<double> yValues = new List<double>();
                    List<string> xValues = new List<string>();
  while (myReader.Read())
                        {{
 xValues.Add(Convert.ToString(myReader[0]));
                                yValues.Add(Convert.ToDouble(myReader[1]));
}
                   

Open in new window


I want to add a if statement in the code above. if myreader(0) < 10 then do something else.
0
 
LVL 9

Author Closing Comment

by:sevensnake77
Comment Utility
got it thanks
0
 

Expert Comment

by:rbgaikwad
Comment Utility
While myReader.Read()
      If myReader(1) < 10 Then
            Other = myReader.GetInt32(1)
      End If
End While
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now