ontextchange事件接受单个字符,它应该接受完整的单词,然后插入到数据库中 [英] ontextchange event accepts single character it should accept full word and then insert into database

查看:42
本文介绍了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();
}

推荐答案

我认为如果焦点是textbox textchange事件发生,无论是单个字母,单词还是一个句子都是一样的。如果我们要插入一个单词make validate,就像textbox文本长度一样大于某个数字你想要作为一个条件。希望它有所帮助。
I think if the focus is out of textbox textchange event occurs whether it is a single letter,a word or a sentence its all the same.If we want to insert a word make validation like textbox text length should greater than some number you want as a condition.Hope it helps.


你可以在文本框中写插入代码离开事件希望它可以帮助你
You can write the insert code in the textbox leave event hope it helps you


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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆