รายละเอียดของการตอบ ::
ตอนนี้ผมเขียนได้แบบนี้แล้วหนะคับ ควรเขียนหรือเพิ่มตรงไหนอีกไหมครับ
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string comportNum = textBox1.Text;
int baudrate = int Convert.ToInt32(textBox2.Text);
serialPort1.PortName = comportNum;
serialPort1.BaudRate = baudrate;
try
{
serialPort1.Open();
}
catch
{
MessageBox.Show("Can't connect Com port");
}
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("user id=username;" +
"password=password;server=serverurl;" +
"Trusted_Connection=yes;" +
"database=database; " +
"connection timeout=30");
}
private void label1_Click(object sender, EventArgs e)
{
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string input = sp.ReadLine();
//try
/*{
myConnection.Open();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}*/
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}