vb6 to c#

  • 12 years ago

     Hi! guys

    Dim rs As New ADODB.Recordset

    My problem is the if statements

    If rs.EOF = True Or rs.BOF = True Then

    rs.AddNew

    rs(
    "Batchno") = 0

    rs("SequenceNumber") = 1

    rs("dayofyear") = Format(outgoingclearingdate, "yyyymmdd")

    Else

    rs(
    "SequenceNumber") = rs("SequenceNumber") + addsno

    rs("Batchno") = rs("Batchno") + addbno

    End If

  • 12 years ago

    I would consider using ADO.Net as your data access mechanism rather than traditional ADO.

    But in answer to your question, your code would look something like this: 

    if (rs.EOF || rs.BOF)
    {
        rs.AddNew();
        rs["Batchno"] = 0;
        //.........
    }
    else
    {
        rs["SequenceNumber"] = rs["SequenceNumber"] + addsno;


     

     

     

  • 12 years ago

    hello!

     That won't work, okay this is what I have,  I want to convert the if statement below to c#

    Dim rs As New ADODB.Recordset

    if (rs.EOF || rs.BOF)

    DataTable dt = new DataTable();

    string sql = "SELECT * FROM DepositSlipSeqNumber where dayofyear = '" + String.Format("{0:yyyyMMdd}", outgoingclearingdate) + "'";

    using (SqlConnection sqlConn = new SqlConnection(Globals.MICLEARConnectString))

    {

    try

    {

    sqlConn.Open();

    using (SqlDataAdapter da = new SqlDataAdapter(sql, sqlConn))

    {

    if ("")

    {

    da.Fill(dt);

    DataRow dr = dt.NewRow();

    dr["Batchno"] = 0;

    dr["SequenceNumber"] = 1;dr["dayofyear"] = String.Format("{0:yyyyMMdd}", outgoingclearingdate);

    dt.Rows.Add(dr);

     

    }

    else

    {

     

    }

     

    }

    }

    catch (Exception x)

    {

    global.LoadErrorScreen(x,
    new System.Diagnostics.StackTrace());

    }

    }

  • 12 years ago
  • 12 years ago

    When you say that the following syntax doesn't work, how exactly does it not work? What errors do you get?  

    if (rs.EOF || rs.BOF)
    {
    .....
    }
     

  • 12 years ago

    C# doesn't have EOF(End of file) or BOF

    u get EOF dt.rows.count-1 

  • 12 years ago

    I agree that doing a dt.rows.count is the best way to achieve your requirement and I'm glad that you've resolved it. 

    However, my understanding was that you've declared rs declared as an ADODB.Recordset and EOF and BOF are valid properties for an ADO Recordset. This is the reason why I was interested in why the code didn't work.

  • 12 years ago

    no, I'm using a datatable- when ur converting vb6 to C# recordset becomes, a dataset or datatable

  • 12 years ago

    yes - that's the gist of what I was getting at when I suggested ADO.Net above. Anyway, I'm glad it works and it sounds as though it's been a good learning experience!

  • 12 years ago

    Eish! you know the last time i did VB6 was in 2004 at varsity, my current project is to convert CITI Bank applications from vb6 to c# at least now i'm already done with the forms. From there i'm gona start with ABSA bank.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic