Solved

if statement c#

Posted on 2013-12-26
8
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

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

Author Comment

by:sevensnake77
ID: 39740634
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
ID: 39740636
Even the c# code comes out as error when I use the less than sign with an integer.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Assisted Solution

by:13Shadow
13Shadow earned 500 total points
ID: 39740656
What are you trying to do in this statement?  If sqlDR("ttt") < 10 Then
0
 
LVL 3

Accepted Solution

by:
13Shadow earned 500 total points
ID: 39740715
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
ID: 39740741
  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
ID: 39740746
got it thanks
0
 

Expert Comment

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

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…

749 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