Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

if statement c#

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
Seven price
Asked:
Seven price
  • 4
  • 3
2 Solutions
 
13ShadowCommented:
The code you posted is C#. Are you asking for the vb equivalent?
0
 
Seven priceFull StackAuthor Commented:
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
 
Seven priceFull StackAuthor Commented:
Even the c# code comes out as error when I use the less than sign with an integer.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
13ShadowCommented:
What are you trying to do in this statement?  If sqlDR("ttt") < 10 Then
0
 
13ShadowCommented:
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
 
Seven priceFull StackAuthor Commented:
  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
 
Seven priceFull StackAuthor Commented:
got it thanks
0
 
rbgaikwadCommented:
While myReader.Read()
      If myReader(1) < 10 Then
            Other = myReader.GetInt32(1)
      End If
End While
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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