Solved

Convert VB to C#

Posted on 2011-02-11
18
351 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 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