WPF中怎么显示C#连接数据库

琥珀_阳 2014-10-30 11:07:54
刚刚学WPF不知道怎么利用WPF来显示C# 连接数据库当中的数据,求指导
最好能给代码,让我学习下,谢谢了
...全文
437 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
湖中仙人 2015-11-24
  • 打赏
  • 举报
回复
以前没学过WPF,怎么看完上面的代码感觉这个和Web好像,无论是前端还是后端
琥珀_阳 2014-10-30
  • 打赏
  • 举报
回复
引用 7 楼 wind_cloud2011 的回复:
代码差不多吧,连接部分修改为mysql的连接 引入命名空间;看一下这例子,http://www.wpf8.net/news/Data/201303/43.html
谢谢了
wind_cloud2011 2014-10-30
  • 打赏
  • 举报
回复
代码差不多吧,连接部分修改为mysql的连接 引入命名空间;看一下这例子,http://www.wpf8.net/news/Data/201303/43.html
琥珀_阳 2014-10-30
  • 打赏
  • 举报
回复
引用 5 楼 wind_cloud2011 的回复:
前台代码: <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; }
你这个是SQL的数据库吧,能说下Mysql怎么改么,不是很懂啊
wind_cloud2011 2014-10-30
  • 打赏
  • 举报
回复
前台代码: <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; }
琥珀_阳 2014-10-30
  • 打赏
  • 举报
回复
引用 3 楼 duanzi_peng 的回复:
使用DataGrid,TreeView,ListBox等集合控件显示。
可是在程序中,添加数据库文件的时候,根本添加不进去
琥珀_阳 2014-10-30
  • 打赏
  • 举报
回复
引用 1 楼 feiyun0112 的回复:
http://msdn.microsoft.com/zh-cn/library/ms771622%28v=vs.90%29.aspx
我想看下代码,我用的Mysql数据库,在程序中向数据库中添加数据可以,但是显示不出来
  • 打赏
  • 举报
回复
使用DataGrid,TreeView,ListBox等集合控件显示。
feiyun0112 2014-10-30
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/zh-cn/library/ms771622%28v=vs.90%29.aspx

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧