.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Convert VB Code to working C# code

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :Windows Application
Hello. I am a beginner and I'm trying to work my way through the MSDN  beginner tutorials. The lesson I am working on had to do with transferring info to another page using a Session object. The example video is written in VB code. I tried to write this part of the lesson in C# code and where the VB code works I am getting an Error message in C# code saying 'The name 'Session' does not exist in the current context' and hence the program will not compile. here is VB Code on default.aspx page     Protected Sub nextButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles nextButton.Click     Dim bill As New Billing bill.FirstName = firstNameTextbox.Text Session.Add(   "billingInformation", bill) Response.Redirect(   "SessionResult.aspx") End Sub VB SessionResult.aspx code is:     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load     Dim bill As Billing = Session("billingInformation")     Dim sb As New System.Text.StringBuilder() sb.Append(   "First Name: ") sb.Append(bill.FirstName) sb.Append(   "<br>") Response.Write(sb.ToString())     End Sub My C# code looks like this for default.aspx page and SessionResult.aspx page &nb

View Complete Post

More Related Resource Links

Want to convert the code from c# to asp

  1.  WebRequest myWebRequest = WebRequest.Create(URL);  
  2.                 WebResponse myWebResponse = myWebRequest.GetResponse();  
  3.                 Stream ReceiveStream = myWebResponse.GetResponseStream();  
  4.                 Encoding encode = System.Text.Encoding.GetEncoding("utf-8");  
  5.                 StreamReader readStream = new StreamReader(ReceiveStream, encode);  
  6.                 string strResponse = readStream.ReadToEnd();  
  7.                 Response.Write("Response from site"

Code write file asp.net 2.0 is working in firefox but IE not working.

If Not IsDBNull(ext) Then                                        ext = LCase(ext)                                    End If                                    Select Case ext                                        'Case ".htm", ".html"                                        '    type = "text/HTML"                   

convert to vb.net code

can any one convert this code to vb.net code please HtmlForm form = (HtmlForm) this.FindControl("Form1"); foreach (Control ctrl in form.Controls) { If (ctrl Is TextBox) Then ((TextBox) ctrl).Text = string.Empty; ElseIf (ctrl Is DropDownList) Then ((DropDownList)ctrl).SelectedIndex = 0; } thanks  

convert client vbscript code to server side

Hi There, we have some .htm pages with client side vbscript,the code is pasted below, we want to get this page run on the server side so that we can access this from a URL, can you please advice how convert this code to be able to run on the server side. Client side code: <HTML><HEAD><TITLE>Select Module</TITLE> <SCRIPT LANGUAGE="VBScript" ><!--     Option Explicit        Dim College    Dim Modules    Dim ModulesArr    Dim counter    Dim MyModules         Set College = Top.App.ActiveCollege    Set Modules = College.Modules     'Sorts the ModulesArr Array by module name.    Sub SortModules(StartPosition, EndPosition)        Dim I, J        Dim CurrName, CurrIndex        For I = StartPosition to EndPosition            J = I            CurrIndex = ModulesArr(J, 0)            CurrName = ModulesArr(J, 1)             'while Mod

Working with Code Snippets in VS.NET

INTRODUCTION Creating code snippets using VS.NET is very useful tip because it may help you when you need to write code repeatedly within your applications. For instance, we may use try catch finally block very often. Rather than writing the complete code-block manually, we may save it as a Code Snippet, then use it anywhere we want. In this blog post, I will show you how to create, save and use Code Snippets, where you will see why Code Snippets are extremely useful, especially if you know that you may have various cases where you will apply such or similar code-blocks. WORKING WITH EXISTING VS.NET CODE SNIPPETS Microsoft has provided us with code snippets that developers use in most of the cases. In order to see the already existing code-snippets, in code-behind of your .net application, use the following shortcut keys: CTRL+K+X Insert Snippet will appear you can select one of the given folders, and some predefined code snippets will appear The line above the snippets shows the path to the snippet (1) where you can write the shortcut key of the snippet you want to insert (for faster approach). In our case, we select the try (2) snippet, which will insert the following code:         void MyMethod()         {            &nbs

convert asp.net code to diagram

it is very hard to read exist asp.net code. but view diagram is very easy. please explain about convert asp.net code to diagram.

Ldap authenication code is not working with IIS but works with Visual Studio developement webserver

Hi,I have weird issue here, I have a method that  takes a login Id and authenticates with LDAP active directory and returns the employee Id.It works great when I run the application in Visual studio 2008 ( it uses the default visual studio developement webserver). The code authenitcates the login id and returns emp Id perfectly. But the problem comes when I publish the code to the Local IIS in my developement PC.public string GetEastWestTeamMembersEmployeeID(string loginID)        {            string domain = string.Empty;            string login = string.Empty;            int position = loginID.IndexOf(@"\");            string empid = "";                  System.DirectoryServices.DirectoryEntry directoryEntry = null;            if (position >= 0)            {                domain = loginID.Substring(0, position);    &n

convert image to rtf code

how can i convert image to rtf code

Code in an event handler not working when used with system reflection.

Hi, I am presently writing an application that uses an MDI form with a ToolStrip on it. I have the need to build the menu items dynamically using an XML file. The format of the XML file is as follows: <ContextMenu EventHandlerHost="vFrmPDUsetup"> <!-- These styles will be applied to the menu items. Individual menu item styles can be override by defining as an attibute to the specific menu item, see below --> <Style> <MenuStripBackColour>Transparent</MenuStripBackColour> <BackColour></BackColour> <ForeColour>Chartreuse</ForeColour> <BackImage></BackImage> <!-- Must exist in Images folder --> <FontName>Tahoma</FontName> <FontSize>10</FontSize> <FontStyle>Bold</FontStyle> </Style> <!-- Attributes: Key = Resource Key name in resource file Image = image to display before text, image must exist in Images folder BackImage = background image, image must exist in Images folder BackColour = background colour as colour name ForeColour = foreground colour as colour name FontSize = size of font as value Seperator = add a menu seperator OnClick = click event pointing to the event handler method which must be defined as the MenuItem_ + <attibute value> &

Format Code D0 is not working in SSRS 2008


We are trying to migrate all our RDL from SSRS 2005 to SSRS 2008.

In the rdl’s we defined format code for a  text box as “D0”  which is working fine in SQL 2005.

While migrating the rdl’s to 2008 it is not working and data is showing for that text box as “#Error”.

How to resolve this . I am having around 1000+ rdl’s to update with proper format string.

If I open the Rdl in BIDS I am getting below error.


[rsInvalidFormatString] The Format value for the textrun ‘textbox1_0_13.Paragraphs[0].TextRuns[0]’ is not valid. Format specifier was invalid.

[rsRuntimeErrorInExpression] The Value expression for

Help Needed working our sp from vb.net code behind


I have a formview and am trying to run this code behind but keep getting this error

Procedure or function 'spCBI_ClientUpd' expects parameter '@op_status', which was not supplied


    Protected Function UpdateClientAdmin() As String
        ' SP UPDATE ClientAdmin 

        Dim ReturnValue As String = String.Empty
        Dim SQL_Connection As New SQL.SqlConnection
        Dim SQL_Command As New SQL.SqlCommand
        SQL_Connection = New SQL.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("CashbacsMainConnectionString").ConnectionString)
            SQL_Command.CommandText = "CASHBACSMAIN.dbo.spCBI_ClientUpd"
            Dim pLicence As New SQL.SqlParameter("@Licence", Data.SqlDbType.VarChar, 6)
            pLicence.Value = TxtLicence.ToString
            pLicence.Direction = Data.ParameterDirection.Input

            Dim pCompany As New SQL.SqlParameter("@CompanyName", Data.SqlDbType.VarChar, 6)
            pCompany.Value = CType(FormView1.FindControl("CompanyNameTextBox"), TextBox).Text
            pCompany.Direction = Data.ParameterDirection.Input

AJAX DropDownList won't populate.. error500.. code is working though.


Here's what I have.  I was able to debug and traverse through the webservice and return teh array back into the first call method of: return new CarsService()..  But back in the page_load method, I can't get it to update and show up in the page.  what am I doing wrong?!?!


<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                    <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
                     Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]"  

Code behind feature not working



I am using WSS 3.0 on Win 2003 and SPD 2007.

I have created a list and created a customized the corresponding NewForm.aspx to with different sub headings as there are many columns and named it NewForm_v2.aspx. To this I've added a label and button to test code-behind features.

The problem:

I have created built a class library in VS2005 > assigned the key etc and finished all other formalities. Changed inheritance tags as well in NewForm_v2.apsx. But when I press the button it is not invoking the method present in the class library (The button should change the text in the label)

My next question is how to debug my code-behind? I've read some articles and tried, but could not hit my break point yet ...

Thanks for your help!


convert MVC Contrib code to VB


hi sorry for my bad english

this code for grid for MVC Contrib code project with C#

<%= Html.Grid(Model.People).Columns(column => {

      column.For(x => x.Id).Named("Person ID");

      column.For(x => x.Name);

      column.For(x => x.DateOfBirth).Format("{0:d}");


        .Attributes(style => "width:100%")

      .Empty("There are no people.")

      .RowStart(row => "<tr foo='bar'>") %>

i want translate(convert) it to VB.net ! can you help me ?

Hi,When i try to convert this VB code in code converter i cannot convert to C#?.can any one help me


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ' it is update procedure
        Dim upd As String = "Update order1 set status = '" + DropDownList1.SelectedValue + "' where ocod = '" + DropDownList2.SelectedValue + "'"
        'Dim str As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source = c:\dms.mdb"
        Dim str As String = "Pr

convert code vb.net to c#.net


Please somebody give idea to convert this code from vb.net tp c# .net.

i converted but not understand about namespace which namespace are added , please help me


 Response.ContentType = "application/pdf"
            Dim doc As Document = New Document
            PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + "\2.pdf", FileMode.Create))
            PdfWriter.GetInstance(doc, Response.OutputStream)
            Dim maintable = New PdfPTable(1)

            maintable.DefaultCell.BorderColor = iTextSharp.text.BaseColor.BLACK
            ' maintable.DefaultCell.Height = Convert.ToSingle(306)

            'maintable.DefaultCell.PaddingTop = 10


Code working in Xp bur showing Error in Vista


Hi all.


I am saving two data, One is date and other one is time in SQL server 2005 using asp.net ( VB.net).

I am saving this using following command:

cmd.commandtext = "insert into TABLE1 values ('" + Now.toshortdatestring + "', '" + Now.toshorttimestring + "')"


now while i am using this code in Windows Xp its working properly but in Windows VISTA it is showing some "Data Conversion Error  from string to datetime". 

If i remove the single quotes [ ' ] from the command it is showing error in the value of date and time.

thanks all



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend