private void myPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] data = new byte[myPort.BytesToRead];
myPort.Read(data, 0, myPort.BytesToRead);
string s = Encoding.ASCII.GetString(data);
BarCodeDisplay.Text = s;
string conStr = "Server=.;Database=testDB;Trusted_Connection=SSPI";
SqlConnection myConn = new SqlConnection(conStr);
myConn.Open();
string insertSqlStr = "insert into tb_barcode values('" + s + "')";
SqlCommand myComm = new SqlCommand(insertSqlStr, myConn);
int i=myComm.ExecuteNonQuery();
myConn.Close();
//this.tb_barcodeTableAdapter.Fill(this.testDBDataSet.tb_barcode);
Bind();
}
private void button2_Click(object sender, EventArgs e)
{
myPort.Open();
}
public void Bind()
{
string conStr = "Server=.;Database=testDB;Trusted_Connection=SSPI";
SqlConnection myConn = new SqlConnection(conStr);
myConn.Open();
string selectSqlStr = "select * from tb_barcode";
SqlDataAdapter myda = new SqlDataAdapter(selectSqlStr, myConn);
DataSet myds = new DataSet();
myda.Fill(myds);
dataGridView1.DataSource = myds.Tables[0];
myConn.Close();
}
有大牛,也不会给你注释每条代码。感觉像在整人。。
想到了这个段子..