ฉันกำลังพยายามอ่านข้อมูลจากพอร์ตอนุกรม แสดงข้อมูลในการควบคุมบางส่วน และแทรกข้อมูลลงในฐานข้อมูล
ฉันได้แทรกมันลงในฐานข้อมูลแล้วและมันอ่านได้อย่างถูกต้อง อย่างไรก็ตาม มันไม่ได้เขียนลงในกล่องข้อความอีกต่อไปตั้งแต่ฉันเพิ่มการเปลี่ยนแปลงฐานข้อมูล ฉันจะทำงานทั้งสามนี้ให้สำเร็จพร้อมกันได้อย่างไร ต่อไปนี้เป็นรหัสบางส่วนของฉัน
void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string force = "";
force = serialPort1.ReadExisting().Split('.')[0].ToString();
Invoke(new Action(() => richTextBox1.AppendText(serialPort1.ReadExisting())));
string queryString = "Insert into Table....";
OdbcConnection connection = new OdbcConnection();
connection.ConnectionString = Settings.Default.STIMConnection;
OdbcCommand command = new OdbcCommand(queryString, connection);
command.CommandType = CommandType.Text;
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
connection.Close();
connection.Dispose();
}
}
ขอบคุณล่วงหน้า.