最好能给代码,让我学习下,谢谢了
9 个解决方案
#1
http://msdn.microsoft.com/zh-cn/library/ms771622%28v=vs.90%29.aspx
#2
我想看下代码,我用的Mysql数据库,在程序中向数据库中添加数据可以,但是显示不出来
#3
使用DataGrid,TreeView,ListBox等集合控件显示。
#4
可是在程序中,添加数据库文件的时候,根本添加不进去
#5
前台代码:
<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;
}
<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;
}
#6
你这个是SQL的数据库吧,能说下Mysql怎么改么,不是很懂啊
#7
代码差不多吧,连接部分修改为mysql的连接
引入命名空间;看一下这例子,http://www.wpf8.net/news/Data/201303/43.html
引入命名空间;看一下这例子,http://www.wpf8.net/news/Data/201303/43.html
#8
谢谢了
#9
以前没学过WPF,怎么看完上面的代码感觉这个和Web好像,无论是前端还是后端
#1
http://msdn.microsoft.com/zh-cn/library/ms771622%28v=vs.90%29.aspx
#2
我想看下代码,我用的Mysql数据库,在程序中向数据库中添加数据可以,但是显示不出来
#3
使用DataGrid,TreeView,ListBox等集合控件显示。
#4
可是在程序中,添加数据库文件的时候,根本添加不进去
#5
前台代码:
<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;
}
<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;
}
#6
你这个是SQL的数据库吧,能说下Mysql怎么改么,不是很懂啊
#7
代码差不多吧,连接部分修改为mysql的连接
引入命名空间;看一下这例子,http://www.wpf8.net/news/Data/201303/43.html
引入命名空间;看一下这例子,http://www.wpf8.net/news/Data/201303/43.html
#8
谢谢了
#9
以前没学过WPF,怎么看完上面的代码感觉这个和Web好像,无论是前端还是后端