REF: Simple Binding Problem - Help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: REF: Simple Binding Problem - Help

  1. #1
    Join Date
    Jun 2009
    Posts
    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:

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,256

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center