Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

convert vb.net to C#

Who can help me convert this code from VB.Net to C#?

objCmd = New SqlCommand(strSQL, objConn)
strSQL = "select count (id) from tblUsers where username='" & strArray(1) & "'"
objCmd.CommandText = strSQL

Dim objReader As SqlClient.SqlDataReader
objReader = objCmd.ExecuteReader

objReader.Read()
If objReader(0) > 0 Then
     ......
    objReader.Close()
End If
0
5281
Asked:
5281
  • 4
  • 3
1 Solution
 
dstanley9Commented:
       objCmd = new SqlCommand(strSQL, objConn);
        strSQL = ("select count (id) from tblUsers where username=\'"
                    + (strArray(1) + "\'"));
        objCmd.CommandText = strSQL;
        SqlClient.SqlDataReader objReader;
        objReader = objCmd.ExecuteReader;
        objReader.Read();
        if ((objReader(0) > 0))
        {
            ...
            objReader.Close();
        }
0
 
dstanley9Commented:
0
 
5281Author Commented:
dstanley9,

strArray(1)  -->  This line gives error, if I change to strArray[1], then it is fine.

SqlClient.SqlDataReader objReader;  --> This line gives error, if I change to SqlDataReader objReader, then it is fine.

if ((objReader(0) > 0))   --> this line gives error when compile,  'objReader' denotes a 'variable' where a 'method' was expected, I still don't know how to change this line.  

Thanks.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dstanley9Commented:
use

if (objReader[0] > 0)

To be fair, I just threw in the result of the converter listed above; I guess I should have checked it myslef first :(
0
 
5281Author Commented:
when I compile, it give this error message for line if (objReader[0] > 0)
Operator '>' cannot be applied to operands of type 'object' and 'int'
How to solve that problem?
0
 
dstanley9Commented:
if ((int)objReader[0] > 0)
0
 
5281Author Commented:
Thanks dstanley9.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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