TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Lm Martiness
NA
107
8.1k
Inserting data from two forms into sql table
May 20 2020 1:26 PM
I am developing a small pos application where user can make payments and save db. Until now I stored data from one form(datagridview, textboxes etc), but now I decided to add one more form (for payments and the change). The idea is that the user call data from db in datagridview(***barcode, qty, name, price, total, vat et***c) , then press the btnpayment(***opens the 2nd form***), then the user give the the required data(give payment), then after clicking the pay button the data from two forms should be inserted into sql table
Now I want to save data from two forms into sql db in same time using same stored procedures.
Before adding the 2nd form I used this code to insert data:
try
{
conn.Open();
foreach (DataGridViewRow row in dtgartikuj.Rows)
{
if (!row.IsNewRow)
{
SqlCommand cmd = new SqlCommand("insertfaturimi", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("@nrfatures", int.Parse(txtnrfatures.Text)));
cmd.Parameters.Add(new SqlParameter("@klienti", cmbklienti.Text));
cmd.Parameters.Add(new SqlParameter("@pagesa", faturimi));
cmd.Parameters.Add(new SqlParameter("@nentotali", txttotali.Text));
cmd.Parameters.Add(new SqlParameter("@zbritje", txtzbritja.Text));
cmd.Parameters.Add(new SqlParameter("@totali", totali.Text));
cmd.Parameters.Add(new SqlParameter("@vleratvsh", textBox1.Text));
cmd.Parameters.Add(new SqlParameter("@nrartikujve", lblnumri.Text));
cmd.Parameters.Add(new SqlParameter("@kasieri", lbluser.Text));
cmd.Parameters.Add(new SqlParameter("@koha", DateTime.Now));
cmd.Parameters.Add(new SqlParameter("@barkodi", row.Cells[0].Value));
cmd.Parameters.Add(new SqlParameter("@emertimi", row.Cells[1].Value));
cmd.Parameters.Add(new SqlParameter("@sasia", row.Cells[2].Value));
cmd.Parameters.Add(new SqlParameter("@tvsh", row.Cells[4].Value));
cmd.Parameters.Add(new SqlParameter("@cmimi", row.Cells[3].Value));
cmd.Parameters.Add(new SqlParameter("@totalipcs", row.Cells[5].Value));
cmd.Parameters.Add(new SqlParameter("@vlerapatvshpcs", row.Cells[6].Value));
cmd.Parameters.Add(new SqlParameter("@vleraetvshpcs", row.Cells[7].Value));
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Faturimi deshtoi" + ex.ToString());
}
finally
{
conn.Close();
}
The 2nd form has some textboxes (payments and change). Now upper code I want to put into 2nd form insert button , but don't know how to link two forms together. My question is what should I change in upper code to be able to put in 2nd form insert button, then insert 2 forms in same time
Reply
Answers (
3
)
JSON Response Error
Want to learn latest technologies