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);
        }


    }
}

}`


Visual Studio Windows Forms C# Interop.Excel - Excel Class Object

I have created a C# Windows Form project in Visual Studio and I am trying to work with an Excel workbook via interop.excel. I have created a custom "excel class" and created an object of it in my Form1. What I am struggling with is whether it is possible to open an excel workbook via a button press, i.e. create the class object from a button press, and then be able to use that object in other button presses. Two versions of code are shown below. One works. One does not. The one that works just opens the Excel workbook when the program is launched. The other attempts to use a button press on the form to open the workbook after the program is launched. In the code that does not work, the object "does not exist in the current context". Any help on how to make the button press code work is most appreciated!

I have created a C# Windows Form project in Visual Studio and I am trying to work with an Excel workbook via interop.excel. I have created a custom "excel class" and created an object of it in my Form1. What I am struggling with is whether it is possible to open an excel workbook via a button press, i.e. create the class object from a button press, and then be able to use that object in other button presses. Two versions of code are shown below. One works. One does not. The one that works just opens the Excel workbook when the program is launched. The other attempts to use a button press on the form to open the workbook after the program is launched. In the code that does not work, the object "does not exist in the current context". Any help on how to make the button press code work is most appreciated!

This code works:

namespace XLtest1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
ExcelClass ex  = new ExcelClass(@"C:\path\TestBook.xlsx", 1);

private void ReadCell_Click(object sender, EventArgs e)
{
    ex.ReadCell();
}

...

This code does not:

namespace XLtest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public void OpenFile()
{
    ExcelClass ex  = new ExcelClass(@"C:\path\TestBook.xlsx", 1);
}

private void OpenWorkbook_Click(object sender, EventArgs e)
{
  OpenFile();
}

private void ReadCell_Click(object sender, EventArgs e)
{
    ex.ReadCell(); // "ex" does not exist in the current context 
}


C/C++ vs. Rust: A developer’s perspective

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Originally published by Maourice Gonzalez at https://www.onmsft.com

C++ is an incredibly fast and efficient programming language. Its versatility knows no bounds and its maturity ensures support and reliability are second to none. Code developed in C++ is also extremely portable, all major operating systems support it. Many developers begin their coding journey with the language, and this is no coincidence. Being object-oriented means it does a very good job of teaching concepts like classes, inheritance, abstraction, encapsulation and polymorphism. Its concepts and syntax can be found in modern languages like C#, Java and Rust. It provides a great foundation that serves as a high speed on ramp to the more popular, easier to use and modern alternatives.

Now it’s not all rosy. C++ has a very steep learning curve and requires developers to apply best practices to the letter or risk ending up with unsafe and/or poor performing code. The small footprint of the standard library, while most times considered a benefit, also adds to the level of difficulty. This means successfully using C++ to create useful complex libraries and applications can be challenging. There is also very little offered in terms of memory management, developers must do this themselves. Novice programmers could end up with debugging nightmares as their lack of experience leads to memory corruption and other sticky situations. This last point has lead many companies to explore fast performing, safe and equally powerful alternatives to C++. For today’s Microsoft that means Rust.

The majority of vulnerabilities fixed and with a CVE [Common Vulnerabilities and Exposures] assigned are caused by developers inadvertently inserting memory corruption bugs into their C and C++ code - Gavin Thomas, Microsoft Security Response Center

Rust began as a personal project by a Mozilla employee named Graydon Hoare sometime in 2006. This ambitious project was in pre-release development for almost a decade, finally launching version 1.0 in May 2015. In what seems to be the blink of an eye it has stolen the hearts of hordes of developers going as far as being voted the most loved language four years straight since 2016 in the Stack Overflow Developer Survey.

The hard work has definitely paid off. The end result is very efficient language which is characteristically object oriented. The fact that it was designed to be syntactically similar to C++ makes it very easy to approach. But unlike the aforementioned it was also designed to be memory safe while also employing a form of memory management without the explicit use of garbage collection.

The ugly truth is software development is very much a trial and error endeavor. With that said Rust has gone above and beyond to help us debug our code. The compiler produces extremely intuitive and user friendly error messages along with great direct linking to relevant documentation to aid with troubleshooting. This means if the problem is not evident, most times the answer is a click away. I’ve found myself rarely having to fire up my browser to look for solutions outside of what the Rust compiler offers in terms of explanation and documentation.

Rust does not have a garbage collector but most times still allocates and release memory for you. It’s also designed to be memory safe, unlike C++ which very easily lets you get into trouble with dangling pointers and data races. In contrast Rust employs concepts which help you prevent and avoid such issues.

There are many other factors which have steered me away from C++ and onto Rust. But to be honest it has nothing to do with all the great stuff we’ve just explored. I came to Rust on a journey that began with WebAssembly. What started with me looking for a more efficient alternative to JavaScript for the web turned into figuring out just how powerful Rust turns out to be. From its seamless interop…

Automatically generate binding code between Rust, WebAssembly, and JavaScript APIs. Take advantage of libraries like web-sys that provide pre-packaged bindings for the entire web platform. – Rust website

To how fast and predictable its performance is. Everything in our lives evolves. Our smartphones, our cars, our home appliances, our own bodies. C++ while still incredibly powerful, fast and versatile can only take us so far. There is no harm in exploring alternatives, especially one as exceptional and with as much promise as Rust.

What do you guys think? Have you or would you give Rust a try? Let us know your thoughts in the comments section below.

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading

Why you should move from Node.js to Rust in 2019

Rust Vs. Haskell: Which Language is Best for API Design?

7 reasons why you should learn Rust programming language in 2019

An introduction to Web Development with Rust for Node.js Developers