将导入的Excel数据保存在DataGrid中到sqlite数据库

时间:2019-01-23 00:20:26

标签: c# excel wpf sqlite

我正在尝试将从excel导入的数据保存到datagrid到数据库中。

数据库详细信息:

  • 文件-tensiondata.db
  • 表格-数据

我找不到有关如何执行此操作的足够信息,我已附上以下代码。我什至不确定将其保存到数据库是正确的解决方案。有什么方法可以将数据网格保存在其他地方?

just last one node and none connection -solved

代码:

<Window x:Class="WpfApp1.Window3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp1"
    mc:Ignorable="d"
    Title="Open Excel File for Tension, Velocity or Takeup" Height="550" Width="900">
    <Grid>
        <Image Source="Capture.jpg" VerticalAlignment="Top" Height="68" Margin="5,10,0,0" HorizontalAlignment="Left" Width="75"/>
        <GroupBox x:Name="Options" Header="Options" HorizontalAlignment="Left" Height="62" Margin="85,8,0,0" VerticalAlignment="Top" Width="562">
        </GroupBox>
        <Button x:Name="save_file" Content="Save and Update" HorizontalAlignment="Left" Margin="451,22,0,0" VerticalAlignment="Top" Width="176" Height="40" Click="Button_Click_1" FontSize="16" FontWeight="Bold"/>
        <Button Content="Generate Graph" FontWeight="Bold" HorizontalAlignment="Left" Margin="350,463,0,0" VerticalAlignment="Top" Width="164" Height="29" Click="Button_Click"/>
        <TextBox x:Name="txtFilePath" HorizontalAlignment="Left" Height="24" Margin="189,32,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="233"/>
        <Button Content="Search" FontWeight="Bold" HorizontalAlignment="Left" Margin="100,32,0,0" VerticalAlignment="Top" Width="78" Height="24" x:Name="search_file" Click="Open_Click"/>
        <DataGrid AutoGenerateColumns="True" IsReadOnly="False" HorizontalAlignment="Center" Name="dtGrid" VerticalAlignment="Center" Height="356" Margin="37,83,44,80" Width="811" RenderTransformOrigin="0.529,0.503" />
    </Grid>
</Window>

1 个答案:

答案 0 :(得分:0)

与其他数据库一样,SQLite需要在将记录插入表结构之前对其进行设计。 我建议您阅读SQLite的文档。这会很有用。

并且DataTable可用作数据源。