Solved

Convert VB to C#

Posted on 2011-02-11
18
347 Views
Last Modified: 2013-12-17
Hi experts,

I want to convert following VB Code to C#.
Please help me.

Thanks,


Imports System.Configuration
Imports System.Web.Configuration
Imports Microsoft.VisualBasic

Public Class AppConfiguration

    Public Shared ReadOnly Property GKCConnectionStringSettings() As ConnectionStringSettings
        Get
            Dim connectionStringKey As String = _
                ConfigurationManager.AppSettings.Get("GKCConnectionString")
            Return ConfigurationManager.ConnectionStrings(connectionStringKey)
        End Get
    End Property

End Class


Imports System.Data
Imports Microsoft.VisualBasic

''' <summary>
''' The Content class represents a Content item in the database that can be displayed on the web site.
''' </summary>
Public Class GKCAccount
    Public Shared Function GetForums() As DataSet
        Return GKCAccountDB.GetForums()
    End Function
End Class

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Public Class GKCAccountDB
    Public Shared Function GetForums() As DataSet
        Dim myDataSet As DataSet = New DataSet()
        Dim myFactory As DbProviderFactory = DbProviderFactories.GetFactory(AppConfiguration.GKCConnectionStringSettings.ProviderName)
        Using myConnection As DbConnection = myFactory.CreateConnection()
            myConnection.ConnectionString = AppConfiguration.GKCConnectionStringSettings.ConnectionString
            myConnection.Open()

            Dim myCommand As SqlCommand = New SqlCommand("my_Forums_GetForums", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure

            Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter()
            myDataAdapter.SelectCommand = myCommand
            myDataAdapter.Fill(myDataSet)
            myConnection.Close()
            Return myDataSet
        End Using
End Class


    End Function

0
Comment
Question by:Takeoutdinner
  • 11
  • 7
18 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34876983
You can try this online code convertor
http://www.developerfusion.com/tools/convert/vb-to-csharp/
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Configuration;
using System.Web.Configuration;

public class AppConfiguration
{

	public static ConnectionStringSettings GKCConnectionStringSettings {
		get {
			string connectionStringKey = ConfigurationManager.AppSettings.Get("GKCConnectionString");
			return ConfigurationManager.ConnectionStrings(connectionStringKey);
		}
	}

}

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;

/// <summary>
/// The Content class represents a Content item in the database that can be displayed on the web site.
/// </summary>
public class GKCAccount
{
	public static DataSet GetForums()
	{
		return GKCAccountDB.GetForums();
	}
}


using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Data.Common;

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class GKCAccountDB
{
	public static DataSet GetForums()
	{
		DataSet myDataSet = new DataSet();
		DbProviderFactory myFactory = DbProviderFactories.GetFactory(AppConfiguration.GKCConnectionStringSettings.ProviderName);
		using (DbConnection myConnection = myFactory.CreateConnection()) {
			myConnection.ConnectionString = AppConfiguration.GKCConnectionStringSettings.ConnectionString;
			myConnection.Open();

			SqlCommand myCommand = new SqlCommand("my_Forums_GetForums", myConnection);
			myCommand.CommandType = CommandType.StoredProcedure;

			SqlDataAdapter myDataAdapter = new SqlDataAdapter();
			myDataAdapter.SelectCommand = myCommand;
			myDataAdapter.Fill(myDataSet);
			myConnection.Close();
			return myDataSet;
		}
	}

}

Open in new window

0
 

Author Comment

by:Takeoutdinner
ID: 34876999
Thank you for posting.

I have errors with your advices: Looking forward to hearing answers soon.

1. I changed return line as follows:
  public static ConnectionStringSettings GKCConnectionStringSetting
  {
      get
      {
          string connectionStringKey = ConfigurationManager.AppSettings.Get("GKCConnectionString");
          return ConfigurationManager.ConnectionStrings["GKCConnectionString"];
      }
  }

2.      ForumsDB. has error with red undrline (was GKCAccountDB.) - It says "the name forumdb does not exist in the current context"
public static DataSet GetForums()
    {
        return ForumsDB.GetForums();
    }

3-1. AppConfiguration. has an error with red undrline - It says "the name forumdb does not exist in the current context"
3-2. new SqlCommand("my_Forums_GetForums", myConnection) has an error with red underline.

    public static DataSet GetForums()
    {
        DataSet myDataSet = new DataSet();
        DbProviderFactory myFactory = DbProviderFactories.GetFactory(AppConfiguration.GKCConnectionStringSettings.ProviderName);
        using (DbConnection myConnection = myFactory.CreateConnection())
        {
            myConnection.ConnectionString = AppConfiguration.GKCConnectionStringSettings.ConnectionString;
            myConnection.Open();

            SqlCommand myCommand = new SqlCommand("my_Forums_GetForums", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter myDataAdapter = new SqlDataAdapter();
            myDataAdapter.SelectCommand = myCommand;
            myDataAdapter.Fill(myDataSet);
            myConnection.Close();
            return myDataSet;
        }
    }
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34877005
>>  ForumsDB. has error with red undrline (was GKCAccountDB.) - It says "the name forumdb does not exist in the current context"
It seems that the object 'ForumsDB' is not declared. - Check whether any namespace missing OR declaration missing for that object.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:Takeoutdinner
ID: 34877009
This is ForumsDB:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Data.Common;


/// <summary>
/// Summary description for ForumsDB
/// </summary>
public class ForumsDB
{
    public static DataSet GetForums()
    {
        DataSet myDataSet = new DataSet();
        DbProviderFactory myFactory = DbProviderFactories.GetFactory(AppConfiguration.GKCConnectionStringSettings.ProviderName);
        using (DbConnection myConnection = myFactory.CreateConnection())
        {
            myConnection.ConnectionString = AppConfiguration.GKCConnectionStringSettings.ConnectionString;
            myConnection.Open();

            SqlCommand myCommand = new SqlCommand("my_Forums_GetForums", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter myDataAdapter = new SqlDataAdapter();
            myDataAdapter.SelectCommand = myCommand;
            myDataAdapter.Fill(myDataSet);
            myConnection.Close();
            return myDataSet;
        }
    }

}
0
 

Author Comment

by:Takeoutdinner
ID: 34877026
When I enter AppConfiguration. , there is no follwed by IntelliSense comes up.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34877028
When I tried, this code is working. Check this code
class AppConfiguration
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for AppConfiguration
/// </summary>
public class AppConfiguration
{
	public AppConfiguration()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static ConnectionStringSettings GKCConnectionStringSettings
    {
        get
        {
            string connectionStringKey = ConfigurationManager.AppSettings.Get("GKCConnectionString");
            return ConfigurationManager.ConnectionStrings[connectionStringKey];
        }
    }


}

Open in new window


class GKCAccount
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for GKCAccount
/// </summary>
public class GKCAccount
{
	public GKCAccount()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static DataSet GetForums()
    {
        return GKCAccountDB.GetForums();
    }

}

Open in new window


class GKCAccountDB
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.Common;

/// <summary>
/// Summary description for GKCAccountDB
/// </summary>
public class GKCAccountDB
{
	public GKCAccountDB()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static DataSet GetForums()
    {
        DataSet myDataSet = new DataSet();
        DbProviderFactory myFactory = DbProviderFactories.GetFactory(AppConfiguration.GKCConnectionStringSettings.ProviderName);
        using (DbConnection myConnection = myFactory.CreateConnection())
        {
            myConnection.ConnectionString = AppConfiguration.GKCConnectionStringSettings.ConnectionString;
            myConnection.Open();

            SqlCommand myCommand = new SqlCommand("my_Forums_GetForums");
            myCommand.Connection = (SqlConnection)myConnection;
            myCommand.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter myDataAdapter = new SqlDataAdapter();
            myDataAdapter.SelectCommand = myCommand;
            myDataAdapter.Fill(myDataSet);
            myConnection.Close();
            return myDataSet;
        }
    }

}

Open in new window

0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34877029
Ok. Check my latest post - http:#34877028
0
 

Author Comment

by:Takeoutdinner
ID: 34877035
In GKCAccountDB,
when I enter "AppConfiguration.", it doesn't bring any Intelsense items.
0
 

Author Comment

by:Takeoutdinner
ID: 34877056
Should I enter something prior to AppConfiguration?
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 125 total points
ID: 34877080
Open and check this project
 WebSite15.zip

Raj
0
 

Author Comment

by:Takeoutdinner
ID: 34877098
Hi,

Websites15 itself looks fine.
But when I imported it into my current program, AppConfiguratio. has same error.
Any thoughts?
0
 

Author Comment

by:Takeoutdinner
ID: 34877122
Hi ,

I will start coding with yours. Then I shall know what's wrong with my current codes.
Thanks for your kind help
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34877138
If my code help you, then why couldn't you give me some points!?
0
 

Author Comment

by:Takeoutdinner
ID: 34891771
Sorry. I accepted with many thanks last week. But it was not done. I don't know why. I will do it again.

Thanks again.
0
 

Author Comment

by:Takeoutdinner
ID: 34891823
I still have a problem for closing. Please ask administrator to close with my accept.  It says:
This question already has an auto close request. You must cancel the previous request before creating another.
0
 

Author Comment

by:Takeoutdinner
ID: 34892056
I am very sorry to finalize it last week. I am giving you point with EE's help in chatting.
0
 

Author Closing Comment

by:Takeoutdinner
ID: 34892091
Very sorry.
I closed it with point last week. But it wasn't done properly. So I am closing it again with EE's help in chatting.

Thanks again
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34893413
No probs!
Glad I could help
Raj
0

Featured Post

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.net and XML report from SCCM 5 20
Set value of dynamically created checkboxlist 2 31
InputLanguage 1 25
Sending receiving text messages in vb.net 15 32
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now