Hi,
I have to add a new row to a table in my dataset using the binding source...I have been working on this for weeks and can't figure it out..
I have to enter a customerid in a text box click a button and this will populate the form with the given data for this customer...i then need to fill in the remaining boxes and click add..this should add a new to the dataset...I can't seem to get it to work..it only edits an exising row..
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void fillByCustomerIDToolStripButton_Click(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void customerIDToolStripTextBox_Click(object sender, EventArgs e)
{
}
private void customerIDTextBox_TextChanged(object sender, EventArgs e)
{
btnAdd.Enabled = !String.IsNullOrEmpty(customerIDTextBox.Text);
btnCancel.Enabled = !String.IsNullOrEmpty(customerIDTextBox.Text);
}
private void dateOpenedTextBox_TextChanged(object sender, EventArgs e)
{
}
private void btnAdd_Click(object sender, EventArgs e)
{
this.incidentsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.techSupportDataSet);
if (titleTextBox.Text == "")
{
MessageBox.Show("Title is a required Field. Please enter text to continue");
}
else if (descriptionTextBox.Text == "")
{
MessageBox.Show("Description is a required Field. Please enter text to continue");
}
else if (string.IsNullOrEmpty(productCodeComboBox.Text))
{
MessageBox.Show("You must select a Product to continue.");
}
else
{
MessageBox.Show("Customer: " + nameTextBox.Text + "\n" + "Product: " + productCodeComboBox.Text, "Incident Added.");
}
try
{
}
catch (DBConcurrencyException)
{
MessageBox.Show("A concurrency error occured. " + " Some rows were not updated.", "Concurrency Exception");
this.incidentsTableAdapter.Fill(this.techSupportDataSet.Incidents);
}
catch (DataException ex)
{
MessageBox.Show(ex.Message, ex.GetType().ToString());
incidentsBindingSource.CancelEdit();
}
catch (SqlException ex)
{
MessageBox.Show("DataBase error # " + ex.Number + ": " + ex.Message, ex.GetType().ToString());
}
}
private void customerIDToolStripTextBox1_Click(object sender, EventArgs e)
{
}
private void fillByCustomerIDToolStripButton1_Click(object sender, EventArgs e)
{
try
{
int customerID = Convert.ToInt32(customerIDToolStripTextBox1.Text);
this.customersTableAdapter.FillByCustomerID(this.techSupportDataSet.Customers, customerID);
if (customersBindingSource.Count == 0)
MessageBox.Show("No Customer found with this ID. " + "Please try again.", "Customer Not Found");
else if (customersBindingSource.Count > 0)
this.incidentsBindingSource.AddNew();
dateOpenedTextBox.Text = DateTime.Today.ToString("dd/MM/yyyy");
this.productsTableAdapter.FillByProductCode(this.techSupportDataSet.Products, customerID);
this.incidentsTableAdapter.FillByCustomerID(this.techSupportDataSet.Incidents, customerID);
titleTextBox.Text = "";
descriptionTextBox.Text = "";
}
catch (FormatException)
{
MessageBox.Show("Customer ID must be an integer.", "Entry Error");
}
catch (SqlException ex)
{
MessageBox.Show("DataBase error # " + ex.Number + ": " + ex.Message, ex.GetType().ToString());
}
}
private void customerIDToolStripTextBox1_Click_1(object sender, EventArgs e)
{
}
private void incidentsBindingSource_CurrentChanged(object sender, EventArgs e)
{
}
private void incidentsBindingSource_AddingNew(object sender, AddingNewEventArgs e)
{
}
private void btnCancel_Click(object sender, EventArgs e)
{
customerIDTextBox.Text = "";
nameTextBox.Text = "";
dateOpenedTextBox.Text = "";
productCodeComboBox.Text = "";
titleTextBox.Text = "";
descriptionTextBox.Text = "";
customerIDToolStripTextBox1.Text = "";
}
private void fillByCustomerIDToolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
}
}