WPF 中保存当前 DataGrid 的数据到数据库中问题
前台:
<DataGrid HorizontalAlignment="Left"
Name="dg_datagrid" Height="117"
Margin="209,32,0,0"
VerticalAlignment="Top" Width="232"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=ShipperID}"
Header="编号"/>
<DataGridTextColumn Binding="{Binding Path=CompanyName}"
Header="名称"/>
<DataGridTextColumn Binding="{Binding Path=Phone}"
Header="号码"/>
</DataGrid.Columns>
</DataGrid>
后台:
private void save_Click(object sender, RoutedEventArgs e)
{
dt = (dg_datagrid.ItemsSource as DataView).Table;
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLExpress;Initial Catalog=WPF_for_ado;Integrated Security=True");
SqlCommand cmd = new SqlCommand(sql_load,conn);
sda = new SqlDataAdapter(cmd);
SqlCommandBuilder cb = new SqlCommandBuilder(sda);
cb.RefreshSchema();
sda.Update(dt);
------------------------------------------------->运行的时候,报错
MessageBox.Show("完成保存!", "提示", MessageBoxButton.OK);
&nbs