|
-
Aug 21st, 2011, 11:53 AM
#1
Thread Starter
New Member
[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>
-
Oct 8th, 2011, 12:38 PM
#2
Fanatic Member
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:
<Application x:Class="App"
and
vb Code:
<Window x:Class="Window1"
for the rest i ran it through an online c# to vb converter and got this
vb Code:
Imports System.Data Imports MySql.Data.MySqlClient Namespace DataBind ''' <summary> ''' Interaction logic for Window1.xaml ''' </summary> Public Partial Class Window1 Inherits System.Windows.Window Public Sub New() InitializeComponent() Dim contentsTable As New DataTable() 'Set the connection String Dim connString As [String] = "server=127.0.0.1;uid=root;pwd=password;database=contents;" 'Set the query Dim query As [String] = "SELECT assetno, item, descr, serialno, purchfrom, manuf FROM contents" ' Fill the Set with the data Using conn As New MySqlConnection(connString) 'Passing the query and connection String Dim da As New MySqlDataAdapter(query, conn) da.Fill(contentsTable) End Using ' Set the Data Context DataContext = contentsTable End Sub End Class 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|