Atul Rokade

Atul Rokade

  • NA
  • 141
  • 43.8k

write insert query if auto complete text not found data

Mar 18 2016 2:47 AM
Hi, 
 
Im creating one application having following requirment
1. having two text box party code and partycode1
2. both are auto complete text box , if value not found in partycode or partycode1 then message box will open data not found do you want to create a record if user click yes then insert query should be fire at same time
3. next time if user try to search partycode then name should be come as autocomplete and same time partycode1 also generated if name exist with disable mode ,user cant modified partycode textbox as second time , value should show basis on what user search into partycode textbox
 4. i wrote code on partycode  textchanged event but it is not work which i want exactly so please can you all help me to solve this issue, below code is give 
 
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[0].ToString();--> exception coming this line index was outside the bounds of the array
bc = dr[1].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();