-
June 15th, 2009, 12:01 AM
#1
REF: Simple Binding Problem - Help
I have code which binds to XAML but its not working, do i need to specifically specify the data source in my XAML I am stuck here is my code:
Code Behind:
MySqlConnection connection;
DataSet ds;
MySqlDataAdapter da;
public Window1()
{
InitializeComponent();
connection = new MySqlConnection("server=localhost;Database=testdatabase;Port=3306;uid=root;pwd=password");
connection.Open();
try
{
ds = new DataSet();
da = new MySqlDataAdapter("select FirstName, LastName from personalDetails", connection);
da.Fill(ds, "personalDetails");
grdRoot.DataContext = ds;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
XAML Code:
<Window x:Class="TestApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:TestApplication"
Title="Window1" Height="300" Width="300">
<Grid x:Name="grdRoot">
<Label Height="28" Margin="12,71,0,0" Name="lblFirstName" VerticalAlignment="Top" HorizontalAlignment="Left" Width="62">Fisrt Name</Label>
<TextBox Height="23" Margin="80,73,78,0" Name="txtFirstName" VerticalAlignment="Top" Text="{Binding Path=FirstName}" />
<Label Margin="12,105,0,129" Name="lblLastName" HorizontalAlignment="Left" Width="67">Last Name</Label>
<TextBox Margin="80,105,78,0" Name="txtLastName" Height="23" VerticalAlignment="Top" Text="{Binding Path=LastName}"/>
</Grid>
</Window>
What am i missing out here, the code is not giving errors its just not displying the data:
-
June 15th, 2009, 01:42 AM
#2
Re: REF: Simple Binding Problem - Help
Is MySqlDataAdapter derived from ObservableCollection?
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
|