Roisin 0 Newbie Poster

Hey, So I am trying to add a new row to the database populating it with information from user input on my form..at the moment its only adding one row and updating it everytime I enter new information instead of adding new rows each time?

I think I havae to use the .addNew() but I can't seem to get it to work??
Any ideas would be appreciated..
thanks

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            //this.Validate();
            //this.customersBindingSource.EndEdit();
            //this.incidentsBindingSource.EndEdit();
            //this.productsBindingSource.EndEdit();
            //this.tableAdapterManager.UpdateAll(this.techSupportDataSet);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'techSupportDataSet.Products' table. You can move, or remove it, as needed.
          //  this.productsTableAdapter.Fill(this.techSupportDataSet.Products);
            // TODO: This line of code loads data into the 'techSupportDataSet.Incidents' table. You can move, or remove it, as needed.
           // this.incidentsTableAdapter.Fill(this.techSupportDataSet.Incidents);
            // TODO: This line of code loads data into the 'techSupportDataSet.Customers' table. You can move, or remove it, as needed.
          //  this.customersTableAdapter.Fill(this.techSupportDataSet.Customers);

        }
        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)
        {

        }

        private void dateOpenedTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {

            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.");
            }

          //  this.Validate();
           // this.incidentsBindingSource.AddNew();
            this.incidentsBindingSource.EndEdit();
           // techSupportDataSet ds = (techSupportDataSet)incidentsBindingSource.DataSource;
            this.tableAdapterManager.UpdateAll(this.techSupportDataSet);
        }

        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)
                    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 = "";
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.