Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..
Posted
Comments
dan!sh 22-Jan-13 3:27am    
1. Do not post entire code dump. Post relevant code.
2. Format the post using options available on top of text area.
3. Provide error details.
[no name] 22-Jan-13 3:30am    
what type of error you got..?
ravithejag 22-Jan-13 3:36am    
what is the error?

Here you are not passing fileid value to database.so it showing null error.also because that fileId column is primary key. One thing do ,put fileId column identification specification property to true.and identity incriment as 1.then the fileId value will insert automatically when succesful save.
 
Share this answer
 
No cule what the error is in your source code. Maybe debugging your source code will help?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900