Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am new to windows application.
I need help regarding How to store the value in datagridview received from weight machine through serial port.

i got received the data and displayed in textbox. but my requirement is to display in datagridview or to store directly in sql server 2008r2.
Please help.
Posted
Updated 10-Mar-16 0:50am

1 solution

C#
private SerialPort port = new SerialPort();  //Create New Serial Port
private DataTable dt = new DataTable(); //Create New Data Table for store the Resaving Data from serial port..

private DataGridView dataGridView = new DataGridView(); // create new DatagridView.

public Form1()
{
    InitializeComponent();
//Create event Handler and invoke the Method
    port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
//open the port
    port.Open();
//Get Data from datatable..
    dataGridView.DataSource = dt;
}
// Create Method for read data from serial port and storage to datatable .. 
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    string data = port.ReadExisting();
    DataRow dr = dt.NewRow();
    dr["DataReceived"] = data;
    dt.Rows.Add(dr);
}


I hope my solution its correct fro you..
 
Share this answer
 
Comments
Balakrishna Kuppam 11-Mar-16 0:03am    
Thanks to Sherif Khaleed

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