Solved

Convert VB to C#

Posted on 2011-02-11
18
343 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
Comment Utility
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
Comment Utility
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
Comment Utility
>>  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
 

Author Comment

by:Takeoutdinner
Comment Utility
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
Comment Utility
When I enter AppConfiguration. , there is no follwed by IntelliSense comes up.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
Comment Utility
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
Comment Utility
Ok. Check my latest post - http:#34877028
0
 

Author Comment

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

Author Comment

by:Takeoutdinner
Comment Utility
Should I enter something prior to AppConfiguration?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 23

Accepted Solution

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

Raj
0
 

Author Comment

by:Takeoutdinner
Comment Utility
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
Comment Utility
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
Comment Utility
If my code help you, then why couldn't you give me some points!?
0
 

Author Comment

by:Takeoutdinner
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No probs!
Glad I could help
Raj
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

14 Experts available now in Live!

Get 1:1 Help Now