send data from arduino to a local database in my Pc

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................................................