本文介绍了ontextchange事件接受单个字符,它应该接受完整的单词,然后插入到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文本框有文本框控件ontextchange,当我按下单个字符时它会插入到数据库中,但我想插入要插入的完整单词,但不使用任何按钮,这里是我的代码请为此提供解决方案





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 =从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(姓名已存在......!请输入新名称);

}

else

{

command.CommandText =INSERT INTO tblbarcode(BARCODE)VALUES('+ barcodetxt.Text +');

}

}

}



cnon.Open();

command.Connection = cnon;

command.ExecuteNonQuery();

cnon.Close();

}

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();
}

推荐答案



这篇关于ontextchange事件接受单个字符,它应该接受完整的单词,然后插入到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 19:19