I use Arduino Uno to get an output of a test and each time I want to save the results, how can I connect my arduino with a local database in my Pc, knowing that it will be connected to a graphical interface in C # to show the Result , please I need your help it is urgent :~
how can I connect my arduino with a local database in my Pc
You probably can't. You need some application on the PC that reads the serial port and deals with the database.
knowing that it will be connected to a graphical interface in C # to show the Result
Is "it" the Statue of Liberty?
If u knw C# this will be eassy use SQLCE as database
If you're using C# perhaps you're running Windows. In that case you could use Gobetwino to run a command on the PC in response to messages from the Arduino. The command could use console database utilities to execute an SQL query to insert the data to your database.
Alternatively you can write your own PC application (using C# or whatever other language you prefer) to read messages from the Arduino serial port and parse them to extract the data, and then execute an SQL query to insert that data into the database. C# has a lot of support for database access so that part should be easy, and reading from the serial port is also easy. There are bound to be examples in the playground showing how to do that sort of thing, and there's a whole section of the forum where you can ask for help if you get stuck.
The simplest way is to use PLX-DAQ. This is a freebie macro for Excel which effectively makes into into a terminal. You can use it to make live on-screen graphs.
Theer are alternatives, like here
but I have not tried it yet.
As Peter said. I personally code in C++, and even with the basic components which come with Embarcadero Codegear you could easily read the serial port and parse the values to an SQL database using either the database components or via an ODBC driver using an ADOConnection
PaulS:
how can I connect my arduino with a local database in my Pc
You probably can't. You need some application on the PC that reads the serial port and deals with the database.
exactly , as I have already mentioned , i will use c# to ensure the serial communication between arduino and the Pc
PeterH:
If you're using C# perhaps you're running Windows. In that case you could use Gobetwino to run a command on the PC in response to messages from the Arduino. The command could use console database utilities to execute an SQL query to insert the data to your database.
Thanks a lot PeterH , but I would like if you explain more to me what is going to serve the Gobetwino since I could already see my output in the c# interface.
vsathish:
If u knw C# this will be eassy use SQLCE as database
I am not so talented in c# , besides, I'm supposed to create an interface that will in the intranet, I want to know what I l need if I use C #, I googled and found that I will need ASP.net . can you give me some suggestions !!
I am not so talented in c# , besides, I'm supposed to create an interface that will in the intranet, I want to know what I l need if I use C #,
First, you need to tell us what relational data base system you are going to talk to. MySQL? SQL Server? PostGRE? Oracle?
Most relational database systems have come kind of C# interface that makes communicating with the database easy. (I've used the first two successfully).
PaulS:
I am not so talented in c# , besides, I'm supposed to create an interface that will in the intranet, I want to know what I l need if I use C #,
First, you need to tell us what relational data base system you are going to talk to. MySQL? SQL Server? PostGRE? Oracle?
Most relational database systems have come kind of C# interface that makes communicating with the database easy. (I've used the first two successfully).
Thanks PaulS for thanks for answering.
i will use SQL server
Ingelectro:
PaulS:
I am not so talented in c# , besides, I'm supposed to create an interface that will in the intranet, I want to know what I l need if I use C #,
First, you need to tell us what relational data base system you are going to talk to. MySQL? SQL Server? PostGRE? Oracle?
Most relational database systems have come kind of C# interface that makes communicating with the database easy. (I've used the first two successfully).
I would like to know the exact procedure, how you did it
Ingelectro:
PaulS:
I am not so talented in c# , besides, I'm supposed to create an interface that will in the intranet, I want to know what I l need if I use C #,
First, you need to tell us what relational data base system you are going to talk to. MySQL? SQL Server? PostGRE? Oracle?
Most relational database systems have come kind of C# interface that makes communicating with the database easy. (I've used the first two successfully).
Thanks PaulS for thanks for answering.
i will use SQL server
I would like to know the exact procedure, how you did it
SQL Server is a Microsoft product. So is Visual Studio that is used to create C# applications.
In the .cs file, add a using System.Data.SqlClient; statement to have full access to SqlConnection, DataSet, SqlException, SqlDataAdapter, and other SQL Server interface classes.
If you have SPECIFIC questions, PM me.
PaulS:
SQL Server is a Microsoft product. So is Visual Studio that is used to create C# applications.In the .cs file, add a using System.Data.SqlClient; statement to have full access to SqlConnection, DataSet, SqlException, SqlDataAdapter, and other SQL Server interface classes.
If you have SPECIFIC questions, PM me.
Thank you PaulS .
there will be no problem if i use vs C # 2010 and sql 2005 or 2008 ??
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.Data.SqlServerCe;
using Microsoft.VisualBasic;
namespace PCComm
{
public partial class frmMain : Form
{
SerialPort Port = new SerialPort();
SqlCeConnection sql_con = new SqlCeConnection(@"Data Source=database path");
SqlCeCommand sql_com = new SqlCeCommand();
public frmMain()
{
InitializeComponent();
Port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
}
private void frmMain_Load(object sender, EventArgs e)
{
sql_con.Open();
this.CenterToScreen();
Port.Close();
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
indata = sp.ReadLine();
}
//sql_con.Open();
SqlCeCommand cmd1 = new SqlCeCommand("SELECT name from consumer_details where mobile1 = '" + number + "' ", sql_con);
SqlCeDataReader read = cmd1.ExecuteReader();
//read.Read();
while (read.Read())
{
name = read.GetString(0);
}
if (name == null)
{
//MessageBox.Show("Message from unknown user");
}
SqlCeCommand cmd2 = new SqlCeCommand("SELECT unit_consumed from bill_details where name = '" + name + "' AND month ='" + mon + "' ", sql_con);
SqlCeDataReader cmd2read = cmd2.ExecuteReader();
while (cmd2read.Read())
{
if (!cmd2read.IsDBNull(0))
cmd2data = Convert.ToInt32(cmd2read.GetString(0));
}
if (cmd2data == 0)
{
//sql_con.Close();
checkfun();
}
else
{
reading = Convert.ToInt32(c) + cmd2data;
reading_mul = (reading * 6);
SqlCeCommand cmd3 = new SqlCeCommand("UPDATE bill_details SET unit_consumed = '" + reading + "' where name = '" + name + "' AND month ='" + mon + "' ", sql_con);
cmd3.ExecuteNonQuery();
if (name != null)
{
check();
}
Port.DiscardInBuffer();
Port.DiscardOutBuffer();
//MessageBox.Show("msg" + updata);
}
}
}
}
return;
}
catch (InvalidCastException)
{
}
catch (FormatException)
{
}
catch (InvalidOperationException)
{
//sql_con.Close();
//Thread.Sleep(1000);
//sql_con.Open();
}
}
private void insert_fun()
{
string selectno = null;
string selectname = null;
int month_no = 0;
string select_month = null;
//sql_con.Open();
SqlCeCommand selectcmd = new SqlCeCommand("SELECT cardno,name from bill_details where name = '"+name+"' ", sql_con);
SqlCeDataReader selectread = selectcmd.ExecuteReader();
while (selectread.Read())
{
selectno = selectread.GetString(0);
selectname = selectread.GetString(1);
}
if (selectno != null || selectname != null)
{
//string[] mon_change = mon;
for (int i = 0; i <= 12; i++)
{
if (month_array == mon)
-
{*
-
month_no = i;*
-
// MessageBox.Show(Convert.ToString(i));*
-
}*
-
}*
-
SqlCeCommand month_check_cmd = new SqlCeCommand("select month from bill_details where name = '"+name+"' AND month='"+mon+"' " ,sql_con);*
-
SqlCeDataReader month_check_data = month_check_cmd.ExecuteReader();*
-
while (month_check_data.Read())*
-
{*
-
select_month = month_check_data.GetString(0);*
-
}*
-
if (select_month == null)*
-
{*
-
int reading = Convert.ToInt32(c) + cmd2data;*
-
SqlCeCommand instcmd = new SqlCeCommand("INSERT INTO bill_details(month,[bill_generated_date],unit_consumed,[bill_last_date],cardno,name) values('" + mon + "','1/" + month_no + "/2014','"+ reading +"','15/" + month_no + "/2014'," + selectno + ",'" + selectname + "')", sql_con);*
-
instcmd.ExecuteNonQuery();*
reading_mul = (reading * 6);
-
SqlCeCommand cmd3 = new SqlCeCommand("UPDATE bill_details SET unit_consumed = '" + reading + "' where name = '" + name + "' AND month ='" + mon + "' ", sql_con);*
-
cmd3.ExecuteNonQuery();*
-
if (name != null)*
-
{*
-
check();*
-
}*
-
Port.DiscardInBuffer();*
-
Port.DiscardOutBuffer();*
-
}*
-
else*
-
{*
-
int reading = Convert.ToInt32(c) + cmd2data;*
reading_mul = (reading * 6); -
SqlCeCommand cmd3 = new SqlCeCommand("UPDATE bill_details SET unit_consumed = '" + reading + "' where name = '" + name + "' AND month ='" + mon + "' ", sql_con);*
-
cmd3.ExecuteNonQuery();*
-
if (name != null)*
-
{*
-
check();*
-
}*
-
Port.DiscardInBuffer();*
-
Port.DiscardOutBuffer();*
-
//MessageBox.Show("msg" + updata);*
-
}*
-
}*
-
}*
-
private void exit_Click(object sender, EventArgs e)*
-
{*
-
sql_con.Close();*
-
Port.Close();*
-
this.Hide();*
-
Application.Exit();*
-
}*
this is basic idea................................................