Sarah Nel

Sarah Nel

  • NA
  • 19
  • 0

Win App add Gridview data to database

Aug 18 2010 3:42 AM
Hello,
I'm working on a invoice system, I want data from the form AND data from a GridView to be saved as one record in the database, but when a customer is selected for an invoice and previous invoices hass not been paid these invoices are also showed in the gridview, but I don't want them to save. This is done for printing reasons.

At the moment everything except the gridview is saved.

    private void record_txt_Click(object sender, EventArgs e)
{
string reference = "INV" + Random();
string payRef = "awaiting";

SqlConnection cnn = new SqlConnection(connectionString);

SqlCommand comm = new SqlCommand();
comm.CommandType = CommandType.Text;
comm.Connection = cnn;

comm.CommandText = "INSERT INTO invoice (c_id, date_added, customer, status, items, description, quantity, unit_value, total, notes, notes_internal, ref, payment_ref) VALUES (@c_id, @date_added, @customer, @status, @items, @description, @quantity, @unit_value, @total, @notes, @notes_internal, @ref, @payment_ref)";

comm.Parameters.AddWithValue("@c_id", Int32.Parse(customer_dd.SelectedValue.ToString()));
comm.Parameters.AddWithValue("@date_added", DateTime.Today.ToShortDateString());
comm.Parameters.AddWithValue("@customer", customer_dd.Text);
comm.Parameters.AddWithValue("@status", Int32.Parse(status));
comm.Parameters.AddWithValue("@items", "Item"); // from gridview
comm.Parameters.AddWithValue("@description", "Descrioption"); // from gridview
comm.Parameters.AddWithValue("@quantity", Int32.Parse(("Qty").ToString())); // from gridview
comm.Parameters.AddWithValue("@unit_value", Int32.Parse("Unit_Value")); // from gridview
comm.Parameters.AddWithValue("@total", Int32.Parse("Line_Total")); // from gridview
comm.Parameters.AddWithValue("@notes", notes_txt.Text);
comm.Parameters.AddWithValue("@notes_internal", internal_txt.Text);
comm.Parameters.AddWithValue("@ref", reference);
comm.Parameters.AddWithValue("@payment_ref", payRef);

cnn.Open();
comm.ExecuteNonQuery();
cnn.Close();



Answers (7)