This is my code;
private void btnsave_Click(object sender, EventArgs e)
{
if (txtOffinceNo.Text.Trim() == string.Empty)
{
MessageBox.Show("OffinceNumber cannot be left blank.!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (txtRegNo.Text.Trim() == string.Empty)
{
MessageBox.Show("RegNo cannot be left blank.!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
SqlDataAdapter da = new SqlDataAdapter("Select * From TBL_TXN_XML_DATA ", ConfigurationSettings.AppSettings["TrafficDB"]);
DataSet ds = new DataSet("MastData");
da.FillSchema(ds, SchemaType.Source, "TBL_TXN_XML_DATA");
da.Fill(ds, "TTBL_TXN_XML_DATA");
DataTable dt;
dt = ds.Tables["TBL_TXN_XML_DATA"];
DataRow drCurrent;
try
{
if (Convert.ToInt32(txtOffinceNo.Tag.ToString()) == 0)
txtOffinceNo.Tag = 0;
}
catch (System.NullReferenceException ex)
{
txtOffinceNo.Tag = 0;
}
drCurrent = dt.Rows.Find(Convert.ToInt32(txtOffinceNo.Tag.ToString()));
if (drCurrent != null)
{
drCurrent.BeginEdit();
drCurrent["OffinceNo"] = txtFileNo.Text.Trim();
drCurrent["RegNo"] = txtRegNo.Text.Trim();
drCurrent["PlateType"] = txtPlateType.Text.Trim();
drCurrent["Platecolor"] = txtPlateColorName.Text.Trim();
drCurrent["Regsource"] = txtRegsource.Text.Trim();
drCurrent["vechclass"] = txtVehClass.Text.Trim();
drCurrent.EndEdit();
SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(da);
da.Update(ds, "TTBL_TXN_XML_DATA");
MessageBox.Show("Record updated successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
drCurrent = dt.NewRow();
drCurrent["OffinceNo"] = txtFileNo.Text.Trim();
drCurrent["RegisNo"] = txtRegNo.Text.Trim();
drCurrent["PlateType"] = txtPlateType.Text.Trim();
drCurrent["Platecolor"] = txtPlateColorName.Text.Trim();
drCurrent["Regsource"] = txtRegsource.Text.Trim();
drCurrent["Vehclass"] = txtVehClass.Text.Trim();
dt.Rows.Add(drCurrent);
SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(da);
da.Update(ds, "TBL_TXN_MAIN");
MessageBox.Show("Record saved successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (txtPlateType.Text.Trim() == "999")
{
PanelGCC.Visible = true;
txtCountryCode.Focus();
drCurrent["country"] = txtCountryCode.Text.Trim();
drCurrent["Plate_issued"] = txtPlateIssuedName.Text.Trim();
drCurrent["Platecode"] = txtPlateType.Text.Trim();
drCurrent["Division"] = txtPlateColorName.Text.Trim();
drCurrent["Regtype"] = txtRegsource.Text.Trim();
drCurrent["vehicletype"] = txtVehType.Text.Trim();
drCurrent["vechiclemake"] = txtVehMake.Text.Trim();
drCurrent["vechiclemodel"] = txtVehModel.Text.Trim();
drCurrent["vechiclecolor"] = txtVehcolor.Text.Trim();
drCurrent["vechiclecolor1"] = txtVehColor1.Text.Trim();
drCurrent["Platecolor"] = txtPlateColorGcc.Text.Trim();
dt.Rows.Add(drCurrent);
SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(da);
da.Update(ds, "TBL_TXN_MAIN");
MessageBox.Show("Record saved successfully", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
i click save that time Column 'FileID' does not allow nulls.then i remove primary key.. i change another name i given primary key that time database error came.Errors were encountered during the save process.how to solve this problem..