Saving imported excel data in a datagrid to sqlite database

Saving imported excel data in a datagrid to sqlite database

I'm trying to save the data I have imported from excel into my datagrid to my database. Data base details File - tensiondata.db Table - data I can't find enough information on how to perform this, I've attached the code below. I'm not even certain that saving it to a database is the right solution. Is there a way you can save the datagrid somewhere else?

I'm trying to save the data I have imported from excel into my datagrid to my database. Data base details File - tensiondata.db Table - data I can't find enough information on how to perform this, I've attached the code below. I'm not even certain that saving it to a database is the right solution. Is there a way you can save the datagrid somewhere else?

`<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"&gt;
&lt;Grid&gt;
    &lt;Image Source="Capture.jpg" VerticalAlignment="Top" Height="68" Margin="5,10,0,0" HorizontalAlignment="Left" Width="75"/&gt;


    &lt;GroupBox x:Name="Options" Header="Options" HorizontalAlignment="Left" Height="62" Margin="85,8,0,0" VerticalAlignment="Top" Width="562"&gt;

    &lt;/GroupBox&gt;

    &lt;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"/&gt;
    &lt;Button Content="Generate Graph" FontWeight="Bold" HorizontalAlignment="Left" Margin="350,463,0,0" VerticalAlignment="Top" Width="164" Height="29" Click="Button_Click"/&gt;
    &lt;TextBox x:Name="txtFilePath" HorizontalAlignment="Left" Height="24" Margin="189,32,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="233"/&gt;
    &lt;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"/&gt;
    &lt;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" /&gt;


&lt;/Grid&gt;

</Window>

public partial class Window3 : Window

{
    string dbConnectionString = @"Data Source = tensiondata.db;Version=3;"; // String connection 
    private object con;

    public Window3()
    {
        InitializeComponent();
    }

    private void Open_Click(object sender, RoutedEventArgs e) // Opening Excel file into data grid 
    {
        OpenFileDialog openfile = new OpenFileDialog();
        openfile.DefaultExt = ".xlsx";
        openfile.Filter = "(.xlsx)|*.xlsx";
        //openfile.ShowDialog();

        var browsefile = openfile.ShowDialog();

        if (browsefile == true)
        {
            txtFilePath.Text = openfile.FileName;

            Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook excelBook = excelApp.Workbooks.Open(txtFilePath.Text.ToString(), 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            Microsoft.Office.Interop.Excel.Worksheet excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelBook.Worksheets.get_Item(1); ;
            Microsoft.Office.Interop.Excel.Range excelRange = excelSheet.UsedRange;

            string strCellData = "";
            double douCellData;
            int rowCnt = 0;
            int colCnt = 0;

            DataTable dt = new DataTable();
            for (colCnt = 1; colCnt &lt;= excelRange.Columns.Count; colCnt++)
            {
                string strColumn = "";
                strColumn = (string)(excelRange.Cells[1, colCnt] as Microsoft.Office.Interop.Excel.Range).Value2;
                dt.Columns.Add(strColumn, typeof(string));
            }

            for (rowCnt = 1; rowCnt &lt;= excelRange.Rows.Count; rowCnt++)
            {
                string strData = "";
                for (colCnt = 1; colCnt &lt;= excelRange.Columns.Count; colCnt++)
                {
                    try
                    {
                        strCellData = (string)(excelRange.Cells[rowCnt, colCnt] as Microsoft.Office.Interop.Excel.Range).Value2;
                        strData += strCellData + "|";
                    }
                    catch (Exception ex)
                    {
                        douCellData = (excelRange.Cells[rowCnt, colCnt] as Microsoft.Office.Interop.Excel.Range).Value2;
                        strData += douCellData.ToString() + "|";
                    }
                }
                strData = strData.Remove(strData.Length - 1, 1);
                dt.Rows.Add(strData.Split('|'));
            }

            dtGrid.ItemsSource = dt.DefaultView;


            excelBook.Close(true, null, null);
            excelApp.Quit();
        }
    }

    private void Button_Click(object sender, RoutedEventArgs e) // Next Window Button 
    {
        Window2 sec = new Window2();
        sec.ShowDialog();
    }



    private void Button_Click_1(object sender, RoutedEventArgs e) // Save and update button
    {
        //Open connection to database
        SQLiteConnection SQLiteCon = new SQLiteConnection(dbConnectionString);
        SQLiteCon.Open();

        try
        {


        }

        //SQLiteCon.Close();
        //}

        // while (dr.Read())
        // {


        //  }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }


    }
}

}`


c-sharp excel wpf

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

C. C++. C#. 차이점 알려드림. 5분 순삭. Explain C.C++.C#. Like I'm Five

C. C++. C#. 차이점 알려드림. 5분 순삭. Explain C.C++.C#. Like I'm Five. 아시죠? C는 C++.C# 줄인말이 아니라는거?

Learn how to perform CRUD operations using C Sharp

QuickStart: CRUD Operations in C Sharp. Learn how to perform CRUD operations using C Sharp for MongoDB databases.

Pixel Color Bot in C#, Visual Studio, .NET and WPF

Create a Pixel Color Bot in C# Visual Studio by using the .NET framework and WPF. This C# tutorial guides you through the development process of creating a pixel bot.

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.

Using isdigit() in C/C++

In this article, we'll take a look at using the isdigit() function in C/C++. This is a very simple way to check if any value is a digit or not. Let's look