Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Convert VB to C#

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
Takeoutdinner
Asked:
Takeoutdinner
  • 11
  • 7
1 Solution
 
Rajkumar GsSoftware EngineerCommented:
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
 
TakeoutdinnerAuthor Commented:
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
 
Rajkumar GsSoftware EngineerCommented:
>>  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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
TakeoutdinnerAuthor Commented:
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
 
TakeoutdinnerAuthor Commented:
When I enter AppConfiguration. , there is no follwed by IntelliSense comes up.
0
 
Rajkumar GsSoftware EngineerCommented:
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
 
Rajkumar GsSoftware EngineerCommented:
Ok. Check my latest post - http:#34877028
0
 
TakeoutdinnerAuthor Commented:
In GKCAccountDB,
when I enter "AppConfiguration.", it doesn't bring any Intelsense items.
0
 
TakeoutdinnerAuthor Commented:
Should I enter something prior to AppConfiguration?
0
 
Rajkumar GsSoftware EngineerCommented:
Open and check this project
 WebSite15.zip

Raj
0
 
TakeoutdinnerAuthor Commented:
Hi,

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

I will start coding with yours. Then I shall know what's wrong with my current codes.
Thanks for your kind help
0
 
Rajkumar GsSoftware EngineerCommented:
If my code help you, then why couldn't you give me some points!?
0
 
TakeoutdinnerAuthor Commented:
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
 
TakeoutdinnerAuthor Commented:
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
 
TakeoutdinnerAuthor Commented:
I am very sorry to finalize it last week. I am giving you point with EE's help in chatting.
0
 
TakeoutdinnerAuthor Commented:
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
 
Rajkumar GsSoftware EngineerCommented:
No probs!
Glad I could help
Raj
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 11
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now