自动填充文本框显示错误 [英] Autocomplete textbox showing error

查看:77
本文介绍了自动填充文本框显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



实际上我正在创建一个应用程序,如果值不存在于accdb数据库中,那么在该文本框中有一个自动完成文本框,这样一个pop就会出现记录没有找到你想要创建并在此插入查询之后,我写了代码,但它显示我的异常索引超出了数组的范围,基于自动完成搜索第二个值插入但是两个值都没有插入到我给出的代码中写的TextChanged文本框事件



我尝试过:



string ab =(txtpartycode.Text);

string bc = txtpartycode1.Text;

con = new OleDbConnection(@provider = Microsoft.ACE.OLEDB.12.0; Data Source = E:\Database\BillAndReceipt.accdb; Persist Security Info = False;);

con.Open();

string query =Select Party_Code ,Party_Code1来自Billing;

OleDbCommand cmd1 = ne w OleDbCommand(query,con);

OleDbDataReader dr = cmd1.ExecuteReader();

if(dr.Read())

{

ab = dr [4] .ToString(); - >异常来到这个行索引超出了数组的范围

bc = dr [5] .ToString();

}

else

{

DialogResult dialogResult = MessageBox.Show(找不到数据是否要创建?,数据插入确认,MessageBoxButtons.YesNo,MessageBoxIcon.Information);

if(dialogResult == DialogResult.Yes)

{

string SqlString =插入计费(Party_Code,Party_Code1)值(?, ?);

使用(OleDbCommand cmd = new OleDbCommand(SqlString,con))

{

con.Open();

cmd.CommandType = CommandType.Text;

cmd.Parameters.AddWithValue(@ Party_Code,txtpartycode.Text);

cmd.Parameters。 AddWithValue(@ Party_Code1,txtpartycode1.Text);

int n = cmd.ExecuteNonQuery();

con.Close();

if(n > 0)

{

MessageBox.Show(数据已成功插入,数据已插入,MessageBoxButtons.OK,MessageBoxIcon.Information);

}

else

{

MessageBox.Show(未插入数据,未插入数据,MessageBoxButtons.OK,MessageBoxIcon。信息);

}

}

}

}

con.Close ();

hi all,

actually im creating one application where having one auto complete textbox in that text box if value doesnt exist into accdb database so one pop is coming record not found do you want to create and after this insert query fire , i wrote the code but it showing me exception index was outside the bounds of the array, basis on auto complete search second value inserting but both values not inserted below im giving code which is written TextChanged event of textbox

What I have tried:

string ab =(txtpartycode.Text);
string bc = txtpartycode1.Text;
con = new OleDbConnection(@" provider=Microsoft.ACE.OLEDB.12.0; Data Source=E:\Database\BillAndReceipt.accdb;Persist Security Info=False;");
con.Open();
string query = "Select Party_Code,Party_Code1 from Billing";
OleDbCommand cmd1 = new OleDbCommand(query, con);
OleDbDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
ab = dr[4].ToString();--> exception coming this line index was outside the bounds of the array
bc = dr[5].ToString();
}
else
{
DialogResult dialogResult = MessageBox.Show("Data Not Found Do you want to create?", "Data insert Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dialogResult == DialogResult.Yes)
{
string SqlString = "Insert Into Billing (Party_Code,Party_Code1)Values (?,?)";
using (OleDbCommand cmd = new OleDbCommand(SqlString, con))
{
con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Party_Code", txtpartycode.Text);
cmd.Parameters.AddWithValue("@Party_Code1", txtpartycode1.Text);
int n = cmd.ExecuteNonQuery();
con.Close();
if (n > 0)
{
MessageBox.Show("Data Inserted Successfully", "Data Inserted ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Data Not inserted", "Data not Inserted ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
con.Close();

推荐答案

这是您的查询,从结算中选择Party_Code,Party_Code1 - 您正在选择2列,但之后您尝试引用第5和第6列datareader。您只能引用第0列和第1列。
Here is your query, "Select Party_Code,Party_Code1 from Billing" - You are choosing 2 columns but then you try to reference columns 5 & 6 in the datareader. You can only reference columns 0 and 1.


这篇关于自动填充文本框显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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