I have text box that have textbox control ontextchange, when i press single character it will insert into database, but i want to insert full word to be inserted, but not using any button, here is my code please provide solution for this
private void barcodetxt_TextChanged(object sender, EventArgs e)
{
OleDbConnection cnon = new OleDbConnection();
cnon.ConnectionString = @"Provider= Microsoft.ACE.OLEDB.12.0; Data Source=D:\WindowsFormsApplication1\barcode.accdb";
OleDbCommand command = new OleDbCommand();
string strqur = "select barcode from tblbarcode";
OleDbCommand cmd = new OleDbCommand(strqur,cnon);
OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
string strcode;
string strcodetxt;
strcodetxt = barcodetxt.Text;
if(ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
strcode = Convert.ToString(ds.Tables[0].Rows[i]["barcode"].ToString());
if (strcodetxt == strcode)
{
MessageBox.Show("Name already exists..! please enter new name");
}
else
{
command.CommandText = "INSERT INTO tblbarcode (BARCODE) VALUES('" + barcodetxt.Text + "')";
}
}
}
cnon.Open();
command.Connection = cnon;
command.ExecuteNonQuery();
cnon.Close();
}