Link to home
Start Free TrialLog in
Avatar of MKItani
MKItani

asked on

convert code from vb.net to C#

please convert the below code form vb.net to C#:

If TypeOf e.Errors Is Data.SqlClient.SqlException Then

Dim sqlerr As SqlException = CType(e.Errors.GetBaseException, SqlException)

            Select Case sqlerr.Number

                  Case 2601

                  e.Row.RowError = "Record is in System"

            End Select
Avatar of MKItani
MKItani

ASKER

sorry this is the full code:

Private Sub daWaitingList_OnRowUpdated(ByVal send As Object, ByVal e As SqlRowUpdatedEventArgs) Handles daWaitingList.RowUpdated

 

If e.Status = UpdateStatus.ErrorsOccurred Then

 

Try

 

If TypeOf e.Errors Is Data.SqlClient.SqlException Then

Dim sqlerr As SqlException = CType(e.Errors.GetBaseException, SqlException)

            Select Case sqlerr.Number

                  Case 2601

                  e.Row.RowError = "Record is in System"

            End Select

Else

            e.Row.RowError = e.Errors.Message

End If

Catch

 

End Try
       private void daWaitingList_OnRowUpdated(object send, SqlRowUpdatedEventArgs e)
        {
            if (e.Status == UpdateStatus.ErrorsOccurred)
            {
                try
                {
                    if (e.Errors is System.Data.SqlClient.SqlException)
                    {
                        SqlException sqlerr = e.Errors.GetBaseException() as SqlException;

                        switch (sqlerr.Number)
                        {
                            case 2602:
                                e.Row.RowError = "Record is in System";
                                break;
                        }
                    }
                    else
                    {
                        e.Row.RowError = e.Errors.Message;
                    }
                }
                catch
                {
                }
            }
        }
Btw, in your code you have "Handles daWaitingList.RowUpdated"

in C# you will need to have somewhere in your code to register the  daWaitingList.RowUpdated event and supply it the function that I converted.

I assume that you know how to do that.
Avatar of MKItani

ASKER

Thank you but i don't know how  i can register.
ASKER CERTIFIED SOLUTION
Avatar of saragani
saragani

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Brad Brett
Brad Brett
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial