Results 1 to 2 of 2

Thread: [WPF] conversion from C # to vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    6

    Exclamation [WPF] conversion from C # to vb.net

    Hello guys, I found an example of a program that I want to translate from C# to vb.
    I report below the code, to clarify what it is, I also write xaml!
    App.xaml
    Code:
    <Application x:Class="DataBind.App"
        xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="Window1.xaml"
        >
        <Application.Resources>
             
        </Application.Resources>
    </Application>
    Window1.xaml.cs
    Code:
    using System;
    using System.Data;
    using MySql.Data.MySqlClient;
    
    namespace DataBind
    {
    
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
    
        public partial class Window1 : System.Windows.Window
        {
            public Window1()
            {
                InitializeComponent();
    
                DataTable contentsTable = new DataTable();
    
                 //Set the connection String
                String connString = "server=127.0.0.1;uid=root;pwd=password;database=contents;";
                    
                //Set the query
                String query = "SELECT assetno, item, descr, serialno, purchfrom, manuf FROM contents";
    
                 // Fill the Set with the data
                using (MySqlConnection conn = new MySqlConnection(connString))
                {
                    //Passing the query and connection String
                    MySqlDataAdapter da = new MySqlDataAdapter(query, conn);
                    da.Fill(contentsTable);
                }
    
                 // Set the Data Context
                DataContext = contentsTable;           
            }
        }
    }
    Window1.xaml
    Code:
    <Window x:Class="DataBind.Window1"  
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
       Title="Data Binding Example" Height="220" Width="300"
       WindowStartupLocation="CenterScreen">
        <Grid>  
           <Grid.RowDefinitions>  
              <RowDefinition/>  
              <RowDefinition/>  
              <RowDefinition/>  
              <RowDefinition/>  
              <RowDefinition/> 
                <RowDefinition/>
           </Grid.RowDefinitions>  
          
          <Grid.ColumnDefinitions>  
             <ColumnDefinition Width="75"/>  
             <ColumnDefinition/>  
          </Grid.ColumnDefinitions>  
         
          <Label>Assetno:</Label>  
          <TextBox Grid.Column="1" Text="{Binding Path=assetno}"/>  
          <Label Grid.Row="1">Item:</Label>  
          <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding item}"/>  
          <Label Grid.Row="2">Description:</Label>  
          <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding descr}"/>  
          <Label Grid.Row="3">Serialno:</Label>  
          <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding serialno}"/>  
          <Label Grid.Row="4">Purch. from:</Label>  
          <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding purchfrom}"/> 
          <Label Grid.Row="5">Manuf:</Label>  
          <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding manuf}"/> 
       </Grid>  
    
    </Window>

  2. #2
    Fanatic Member Megalith's Avatar
    Join Date
    Oct 2006
    Location
    Secret location in the UK
    Posts
    879

    Re: [WPF] conversion from C # to vb.net

    the xaml is pretty much the same except for the namespace in the class declaration, not sure why this isn't the same with both but in vb you would use
    vb Code:
    1. <Application x:Class="App"
    and
    vb Code:
    1. <Window x:Class="Window1"
    for the rest i ran it through an online c# to vb converter and got this
    vb Code:
    1. Imports System.Data
    2. Imports MySql.Data.MySqlClient
    3.  
    4. Namespace DataBind
    5.  
    6.     ''' <summary>
    7.     ''' Interaction logic for Window1.xaml
    8.     ''' </summary>
    9.  
    10.     Public Partial Class Window1
    11.         Inherits System.Windows.Window
    12.         Public Sub New()
    13.             InitializeComponent()
    14.  
    15.             Dim contentsTable As New DataTable()
    16.  
    17.             'Set the connection String
    18.             Dim connString As [String] = "server=127.0.0.1;uid=root;pwd=password;database=contents;"
    19.  
    20.             'Set the query
    21.             Dim query As [String] = "SELECT assetno, item, descr, serialno, purchfrom, manuf FROM contents"
    22.  
    23.             ' Fill the Set with the data
    24.             Using conn As New MySqlConnection(connString)
    25.                 'Passing the query and connection String
    26.                 Dim da As New MySqlDataAdapter(query, conn)
    27.                 da.Fill(contentsTable)
    28.             End Using
    29.  
    30.             ' Set the Data Context
    31.             DataContext = contentsTable
    32.         End Sub
    33.     End Class
    34. End Namespace

    ps i haven't tested this but it looks right
    If debugging is the process of removing bugs, then programming must be the process of putting them in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width