• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

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
0
MKItani
Asked:
MKItani
  • 3
  • 2
2 Solutions
 
MKItaniAuthor Commented:
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
0
 
saraganiCommented:
       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
                {
                }
            }
        }
0
 
saraganiCommented:
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MKItaniAuthor Commented:
Thank you but i don't know how  i can register.
0
 
saraganiCommented:
If you click a control on your form, then you have on the properties at the right a sign of a lightning.
If you put your mouse over it, you should see that the tooltip is Events.

Click on that "Lightning".

Now you can see all the events of that Control.

Just look for the RowUpdate event and from the ComboBox choose the function you have converted.
0
 
Mohamed AbowardaSoftware EngineerCommented:
The following tool will help you to convert from VB.NET to C# and C# to VB.NET as well:
http://www.developerfusion.com/tools/convert/vb-to-csharp/
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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