hi all i am new to C#
i am developed Testing utility
currently i received string from Device .
D1U1802200000000000001000000S009000570101640048500851202880033800265003140015000536000280001400048004420013100098002530
and try to save in Access Database .
My problem is that my data is not save in access single record . save data in multipule recode .
i am developed Testing utility
currently i received string from Device .
D1U1802200000000000001000000S009000570101640048500851202880033800265003140015000536000280001400048004420013100098002530
and try to save in Access Database .
My problem is that my data is not save in access single record . save data in multipule recode .
C#:
namespace MYabc21_Final
{
public partial class TestingUtilityForm : TemplateForm
{
OleDbConnection connection = new OleDbConnection();
// String DataOut;
String DataIN;
public TestingUtilityForm()
{
InitializeComponent();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\Interfacing.accdb";
}
private void TestingUtilityForm_Load(object sender, EventArgs e)
{
connection.Open();
connectionStatusLabel.Text = "Connection Establish";
connection.Close();
// Create Function to get Serial Port
string[] ports = SerialPort.GetPortNames();
comPortsComboBox.Items.AddRange(ports);
}
private void openButton_Click(object sender, EventArgs e)
{
try
{
serialPort1.PortName = comPortsComboBox.Text;
serialPort1.BaudRate = Convert.ToInt32(baudComboBox.Text);
serialPort1.DataBits = Convert.ToInt32(dataBitsComboBox.Text);
serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), stopBitsComboBox.Text);
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), parityComboBox.Text);
serialPort1.Open();
progressBar1.Value = 100;
}
catch (Exception Err)
{
MessageBox.Show(Err.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void closeButton_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
progressBar1.Value = 0;
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
DataIN = serialPort1.ReadExisting();
// this.Invoke(new EventHandler(ShowData));
try
{
string databasedata = DataIN;
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "insert into tblData(MYdata) values('"+databasedata+"')";
command.ExecuteNonQuery();
DataIN = null;
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("error"+ex);
}
}
private void ShowData(object sender, EventArgs e)
{
int dataINLength = DataIN.Length;
dataInLengthLabel.Text = String.Format("{0:00}", DataIN.Length);
INdataTextBox.Clear();
INdataTextBox.Text += DataIN;
}
private void clearButton_Click(object sender, EventArgs e)
{
INdataTextBox.Text = "";
dataInLengthLabel.Text = "";
}
private void INdataTextBox_TextChanged(object sender, EventArgs e)
{
int DataOutLength = INdataTextBox.TextLength;
dataInLengthLabel.Text = String.Format("{0:00}", DataOutLength);
}
private void showDataButton_Click(object sender, EventArgs e)
{
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select * from tblData";
command.CommandText = query;
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("error" + ex);
}
}
}
}