Click here to Skip to main content
15,895,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can read the data from arduino uno micro controller and save it in text file using windows forms, but I want to save it in a database table and compare it with another table and display an indication in GUI.I have created sql server database connection too, given an username,password to it.I have gone through LINQ to SQL classes,Dataset,SQL server Database,ADO.Net Entity Framework and i'm really confused what to choose,please help me out.I have installed Sql server and SQL server management studio.

C# code to save and display data:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace lightsapp
{
    public partial class Form1 : Form
    {
        private SerialPort myport;
        
        private string in_data; 

        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void start_btn_Click(object sender, EventArgs e)
        {
            myport = new SerialPort();
            myport.BaudRate = 9600;
            myport.PortName = port_name_tb.Text;
            myport.Parity = Parity.None;
            myport.DataBits = 8;
            myport.StopBits = StopBits.One;
           myport.DataReceived += Myport_DataReceived;

            try
            {
                myport.Open();
                data_tb.Text = "";
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "error");
  }

        }

       private void Myport_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
             in_data = myport.ReadLine();
             this.Invoke(new EventHandler(displaydata_event));

            
        }

       private void displaydata_event(object sender, EventArgs e)
     {
            char[] array= in_data.ToCharArray();
            if(array[0] =='A')
            {

            }
               else if(array[0]=='O')
            {

            }
            else
            data_tb.AppendText(  in_data+"\n");

        }
        
        private void stop_btn_Click(object sender, EventArgs e)
        {
            try
            {
                myport.Close();

            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "error");

            }
        }

        private void save_btn_Click(object sender, EventArgs e)
        {
            try {
                string pathfile = @"C:\Users\afzal\Desktop\data\";
                string filename = "l_data.gpx";
                System.IO.File.WriteAllText(pathfile + filename, data_tb.Text);
                MessageBox.Show("data has been saved to" +pathfile, "savefile");

            }
            catch(Exception ex3)
            {
                MessageBox.Show(ex3.Message, "error");
            }


        }

        private void value_tb_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
Posted
Updated 14-Dec-15 3:06am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900