代码差不多吧,连接部分修改为mysql的连接 引入命名空间;看一下这例子,http://www.wpf8.net/news/Data/201303/43.html
前台代码: <Window x:Class="WpfApplication9.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="343" Width="564"> <Grid> <Button Content="Button" Height="39" HorizontalAlignment="Left" Margin="427,107,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> <DataGrid AutoGenerateColumns="True" Name="datagrid" CanUserAddRows="False" Margin="21,0,170,9" /> </Grid> </Window> 后台: private void button1_Click(object sender, RoutedEventArgs e) { string strConn = "Data Source=192.168.1.2;Initial Catalog=db;User ID=user;password=12345;Integrated Security=False"; SqlConnection conn = new SqlConnection(strConn); conn.Open(); string strSql = ""; SqlDataAdapter myCommand = null; DataSet ds = null; strSql = "SELECT * FROM table"; myCommand = new SqlDataAdapter(strSql, strConn); ds = new DataSet(); myCommand.Fill(ds, "table1"); datagrid.ItemsSource = ds.Tables[0].DefaultView; }
使用DataGrid,TreeView,ListBox等集合控件显示。
http://msdn.microsoft.com/zh-cn/library/ms771622%28v=vs.90%29.aspx
111,092
社区成员
642,554
社区内容
加载中
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧