Sql lite exception failed constraint failed UNIQUE constraint failed: tbllocations.SiteID

  • Thread starter Thread starter mcfee12345
  • Start date Start date
M

mcfee12345

Guest
I am having an issue in editing information that was there before within my database.When ever i want to edit a different

field i get the above error.I am using DB browser for sqlite.Kindly assist on how to resolve it

//set execute query
private void ExecuteQuery(string txtQuery)
{
SetConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
sql_cmd.CommandText = txtQuery;
sql_cmd.ExecuteNonQuery();
sql_con.Close();
}
//set loadDB
private void LoadData()
{
SetConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "select * from tbllocations ";
DB = new SQLiteDataAdapter(CommandText, sql_con);
DS.Reset();
DB.Fill(DS);
DT = DS.Tables[0];
dataGridView1.DataSource = DT;
sql_con.Close();
}
//add
private void buttonadd_Click(object sender, EventArgs e)
{
string txtQuery = "insert into tbllocations ( SiteId,Description,OpsArea,BoxNo,ContractStartDate,ContractEndDate,OBEndDate,OBStartDate)values('" + textBoxSiteID.Text + "','" + textBoxDescription.Text + "','" + textBoxOpsArea.Text + "','" + textBoxBoxNumber.Text + "','" + dateTimePickerContractStartDate.Text + "','" + dateTimePickerContractEndDate.Text + "','" + dateTimePickerOBEndDate.Text + "','" + dateTimePickerOBStartDate.Text + "')";

ExecuteQuery(txtQuery);
LoadData();
}

private void buttonEdit_Click(object sender, EventArgs e)
{
textBoxSiteID.Focus();
//string txtQuery = " update tbllocations set Description = '" + textBoxDescription.Text+"' where SiteId ='"+ textBoxSiteID.Text;
//ExecuteQuery(txtQuery);
//LoadData();


}

Continue reading...
 
Back
Top