How to update datagridview items in c#












0














I want to update invoice and invoice has multiple items i retrieve invoice items from Database to DataGridView now user can remove the items and can add the items and user will click on update button to update the invoice in database.



My Code:



try
{
using (SQLiteConnection con = new SQLiteConnection(AppSettings.ConnectionString()))
{
con.Open();
for (int j = 0; j < dgv.Rows.Count; j++)
{
using (SQLiteCommand sc = new SQLiteCommand("Update Orders Set [Order_No] = @Order_No,[Order_Type] = @Order_Type,[Order_Date] = @Order_Date,[Customer_Name] = @Customer_Name,[Contact] = @Contact,[Adress] = @Adress,[Delivery_Address] = @Delivery_Address,[Rider] = @Rider,[Items] = @Items,[Price] = @Price,[Qty] = @Qty,[Item_Total] = @Item_Total,[Item_Cat] = @Item_Cat,[SubTotal] = @SubTotal,[Discount] = @Discount,[Total_Amount] = @Total_Amount,[Paid_Amount] = @Paid_Amount,[Change_Due] = @Change_Due,[Delivery_Charges] = @Delivery_Charges Where Order_No = '" + Order_No.Text + "' ", con))
{
sc.Parameters.AddWithValue("@Order_No", Order_No.Text);
sc.Parameters.AddWithValue("@Order_Type", Order_Type.Text);
sc.Parameters.AddWithValue("@Order_Date", Order_Date.Text);
sc.Parameters.AddWithValue("@Customer_Name", Customer_Name.Text);
sc.Parameters.AddWithValue("@Contact", Contact.Text);
sc.Parameters.AddWithValue("@Adress", Address.Text);
sc.Parameters.AddWithValue("@Delivery_Address", Delivery_Address.Text);
sc.Parameters.AddWithValue("@Rider", "");
sc.Parameters.AddWithValue("@Items", dgv.Rows[j].Cells[1].Value);
sc.Parameters.AddWithValue("@Price", dgv.Rows[j].Cells[2].Value);
sc.Parameters.AddWithValue("@Qty", dgv.Rows[j].Cells[3].Value);
sc.Parameters.AddWithValue("@Item_Total", dgv.Rows[j].Cells[4].Value);
sc.Parameters.AddWithValue("@Item_Cat", dgv.Rows[j].Cells[5].Value);
sc.Parameters.AddWithValue("@SubTotal", SubTotal.Text);
sc.Parameters.AddWithValue("@Discount", Discount.Text);
sc.Parameters.AddWithValue("@Total_Amount", Total_Amount.Text);
sc.Parameters.AddWithValue("@Paid_Amount", Paid_Amount.Text);
sc.Parameters.AddWithValue("@Change_Due", Change_Due.Text);
sc.Parameters.AddWithValue("@Delivery_Charges", Del_Charges.Text);
sc.ExecuteNonQuery();
}
}

SuccessBox sb = new SuccessBox();
sb.lbl_Change.Text = Change_Due.Text;
sb.label1.Text = "Successfully Updated";
sb.ShowDialog();
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


if i add new item and click on update button so this query replaces my all old items with new one.



Suppose i add Samsung S8 so it willl replace my old items to Samsung S8.



And the result is:



Samsung S8   1   $750
Samsung S8 1 $750
Samsung S8 1 $750
Samsung S8 1 $750


Is there any way to do this?



Note: I am unable to solve this problem 8 days passed now.










share|improve this question




















  • 1




    If you learn about data binding, updating the DB is a single simple method myDataAdapter.Update();
    – WelcomeOverflow
    Nov 13 '18 at 7:20










  • @Disaffected1070452 can you give me any example so i can do it by myself?
    – Beeman
    Nov 13 '18 at 7:36
















0














I want to update invoice and invoice has multiple items i retrieve invoice items from Database to DataGridView now user can remove the items and can add the items and user will click on update button to update the invoice in database.



My Code:



try
{
using (SQLiteConnection con = new SQLiteConnection(AppSettings.ConnectionString()))
{
con.Open();
for (int j = 0; j < dgv.Rows.Count; j++)
{
using (SQLiteCommand sc = new SQLiteCommand("Update Orders Set [Order_No] = @Order_No,[Order_Type] = @Order_Type,[Order_Date] = @Order_Date,[Customer_Name] = @Customer_Name,[Contact] = @Contact,[Adress] = @Adress,[Delivery_Address] = @Delivery_Address,[Rider] = @Rider,[Items] = @Items,[Price] = @Price,[Qty] = @Qty,[Item_Total] = @Item_Total,[Item_Cat] = @Item_Cat,[SubTotal] = @SubTotal,[Discount] = @Discount,[Total_Amount] = @Total_Amount,[Paid_Amount] = @Paid_Amount,[Change_Due] = @Change_Due,[Delivery_Charges] = @Delivery_Charges Where Order_No = '" + Order_No.Text + "' ", con))
{
sc.Parameters.AddWithValue("@Order_No", Order_No.Text);
sc.Parameters.AddWithValue("@Order_Type", Order_Type.Text);
sc.Parameters.AddWithValue("@Order_Date", Order_Date.Text);
sc.Parameters.AddWithValue("@Customer_Name", Customer_Name.Text);
sc.Parameters.AddWithValue("@Contact", Contact.Text);
sc.Parameters.AddWithValue("@Adress", Address.Text);
sc.Parameters.AddWithValue("@Delivery_Address", Delivery_Address.Text);
sc.Parameters.AddWithValue("@Rider", "");
sc.Parameters.AddWithValue("@Items", dgv.Rows[j].Cells[1].Value);
sc.Parameters.AddWithValue("@Price", dgv.Rows[j].Cells[2].Value);
sc.Parameters.AddWithValue("@Qty", dgv.Rows[j].Cells[3].Value);
sc.Parameters.AddWithValue("@Item_Total", dgv.Rows[j].Cells[4].Value);
sc.Parameters.AddWithValue("@Item_Cat", dgv.Rows[j].Cells[5].Value);
sc.Parameters.AddWithValue("@SubTotal", SubTotal.Text);
sc.Parameters.AddWithValue("@Discount", Discount.Text);
sc.Parameters.AddWithValue("@Total_Amount", Total_Amount.Text);
sc.Parameters.AddWithValue("@Paid_Amount", Paid_Amount.Text);
sc.Parameters.AddWithValue("@Change_Due", Change_Due.Text);
sc.Parameters.AddWithValue("@Delivery_Charges", Del_Charges.Text);
sc.ExecuteNonQuery();
}
}

SuccessBox sb = new SuccessBox();
sb.lbl_Change.Text = Change_Due.Text;
sb.label1.Text = "Successfully Updated";
sb.ShowDialog();
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


if i add new item and click on update button so this query replaces my all old items with new one.



Suppose i add Samsung S8 so it willl replace my old items to Samsung S8.



And the result is:



Samsung S8   1   $750
Samsung S8 1 $750
Samsung S8 1 $750
Samsung S8 1 $750


Is there any way to do this?



Note: I am unable to solve this problem 8 days passed now.










share|improve this question




















  • 1




    If you learn about data binding, updating the DB is a single simple method myDataAdapter.Update();
    – WelcomeOverflow
    Nov 13 '18 at 7:20










  • @Disaffected1070452 can you give me any example so i can do it by myself?
    – Beeman
    Nov 13 '18 at 7:36














0












0








0







I want to update invoice and invoice has multiple items i retrieve invoice items from Database to DataGridView now user can remove the items and can add the items and user will click on update button to update the invoice in database.



My Code:



try
{
using (SQLiteConnection con = new SQLiteConnection(AppSettings.ConnectionString()))
{
con.Open();
for (int j = 0; j < dgv.Rows.Count; j++)
{
using (SQLiteCommand sc = new SQLiteCommand("Update Orders Set [Order_No] = @Order_No,[Order_Type] = @Order_Type,[Order_Date] = @Order_Date,[Customer_Name] = @Customer_Name,[Contact] = @Contact,[Adress] = @Adress,[Delivery_Address] = @Delivery_Address,[Rider] = @Rider,[Items] = @Items,[Price] = @Price,[Qty] = @Qty,[Item_Total] = @Item_Total,[Item_Cat] = @Item_Cat,[SubTotal] = @SubTotal,[Discount] = @Discount,[Total_Amount] = @Total_Amount,[Paid_Amount] = @Paid_Amount,[Change_Due] = @Change_Due,[Delivery_Charges] = @Delivery_Charges Where Order_No = '" + Order_No.Text + "' ", con))
{
sc.Parameters.AddWithValue("@Order_No", Order_No.Text);
sc.Parameters.AddWithValue("@Order_Type", Order_Type.Text);
sc.Parameters.AddWithValue("@Order_Date", Order_Date.Text);
sc.Parameters.AddWithValue("@Customer_Name", Customer_Name.Text);
sc.Parameters.AddWithValue("@Contact", Contact.Text);
sc.Parameters.AddWithValue("@Adress", Address.Text);
sc.Parameters.AddWithValue("@Delivery_Address", Delivery_Address.Text);
sc.Parameters.AddWithValue("@Rider", "");
sc.Parameters.AddWithValue("@Items", dgv.Rows[j].Cells[1].Value);
sc.Parameters.AddWithValue("@Price", dgv.Rows[j].Cells[2].Value);
sc.Parameters.AddWithValue("@Qty", dgv.Rows[j].Cells[3].Value);
sc.Parameters.AddWithValue("@Item_Total", dgv.Rows[j].Cells[4].Value);
sc.Parameters.AddWithValue("@Item_Cat", dgv.Rows[j].Cells[5].Value);
sc.Parameters.AddWithValue("@SubTotal", SubTotal.Text);
sc.Parameters.AddWithValue("@Discount", Discount.Text);
sc.Parameters.AddWithValue("@Total_Amount", Total_Amount.Text);
sc.Parameters.AddWithValue("@Paid_Amount", Paid_Amount.Text);
sc.Parameters.AddWithValue("@Change_Due", Change_Due.Text);
sc.Parameters.AddWithValue("@Delivery_Charges", Del_Charges.Text);
sc.ExecuteNonQuery();
}
}

SuccessBox sb = new SuccessBox();
sb.lbl_Change.Text = Change_Due.Text;
sb.label1.Text = "Successfully Updated";
sb.ShowDialog();
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


if i add new item and click on update button so this query replaces my all old items with new one.



Suppose i add Samsung S8 so it willl replace my old items to Samsung S8.



And the result is:



Samsung S8   1   $750
Samsung S8 1 $750
Samsung S8 1 $750
Samsung S8 1 $750


Is there any way to do this?



Note: I am unable to solve this problem 8 days passed now.










share|improve this question















I want to update invoice and invoice has multiple items i retrieve invoice items from Database to DataGridView now user can remove the items and can add the items and user will click on update button to update the invoice in database.



My Code:



try
{
using (SQLiteConnection con = new SQLiteConnection(AppSettings.ConnectionString()))
{
con.Open();
for (int j = 0; j < dgv.Rows.Count; j++)
{
using (SQLiteCommand sc = new SQLiteCommand("Update Orders Set [Order_No] = @Order_No,[Order_Type] = @Order_Type,[Order_Date] = @Order_Date,[Customer_Name] = @Customer_Name,[Contact] = @Contact,[Adress] = @Adress,[Delivery_Address] = @Delivery_Address,[Rider] = @Rider,[Items] = @Items,[Price] = @Price,[Qty] = @Qty,[Item_Total] = @Item_Total,[Item_Cat] = @Item_Cat,[SubTotal] = @SubTotal,[Discount] = @Discount,[Total_Amount] = @Total_Amount,[Paid_Amount] = @Paid_Amount,[Change_Due] = @Change_Due,[Delivery_Charges] = @Delivery_Charges Where Order_No = '" + Order_No.Text + "' ", con))
{
sc.Parameters.AddWithValue("@Order_No", Order_No.Text);
sc.Parameters.AddWithValue("@Order_Type", Order_Type.Text);
sc.Parameters.AddWithValue("@Order_Date", Order_Date.Text);
sc.Parameters.AddWithValue("@Customer_Name", Customer_Name.Text);
sc.Parameters.AddWithValue("@Contact", Contact.Text);
sc.Parameters.AddWithValue("@Adress", Address.Text);
sc.Parameters.AddWithValue("@Delivery_Address", Delivery_Address.Text);
sc.Parameters.AddWithValue("@Rider", "");
sc.Parameters.AddWithValue("@Items", dgv.Rows[j].Cells[1].Value);
sc.Parameters.AddWithValue("@Price", dgv.Rows[j].Cells[2].Value);
sc.Parameters.AddWithValue("@Qty", dgv.Rows[j].Cells[3].Value);
sc.Parameters.AddWithValue("@Item_Total", dgv.Rows[j].Cells[4].Value);
sc.Parameters.AddWithValue("@Item_Cat", dgv.Rows[j].Cells[5].Value);
sc.Parameters.AddWithValue("@SubTotal", SubTotal.Text);
sc.Parameters.AddWithValue("@Discount", Discount.Text);
sc.Parameters.AddWithValue("@Total_Amount", Total_Amount.Text);
sc.Parameters.AddWithValue("@Paid_Amount", Paid_Amount.Text);
sc.Parameters.AddWithValue("@Change_Due", Change_Due.Text);
sc.Parameters.AddWithValue("@Delivery_Charges", Del_Charges.Text);
sc.ExecuteNonQuery();
}
}

SuccessBox sb = new SuccessBox();
sb.lbl_Change.Text = Change_Due.Text;
sb.label1.Text = "Successfully Updated";
sb.ShowDialog();
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


if i add new item and click on update button so this query replaces my all old items with new one.



Suppose i add Samsung S8 so it willl replace my old items to Samsung S8.



And the result is:



Samsung S8   1   $750
Samsung S8 1 $750
Samsung S8 1 $750
Samsung S8 1 $750


Is there any way to do this?



Note: I am unable to solve this problem 8 days passed now.







c# sqlite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 10:24







Beeman

















asked Nov 13 '18 at 6:19









BeemanBeeman

83




83








  • 1




    If you learn about data binding, updating the DB is a single simple method myDataAdapter.Update();
    – WelcomeOverflow
    Nov 13 '18 at 7:20










  • @Disaffected1070452 can you give me any example so i can do it by myself?
    – Beeman
    Nov 13 '18 at 7:36














  • 1




    If you learn about data binding, updating the DB is a single simple method myDataAdapter.Update();
    – WelcomeOverflow
    Nov 13 '18 at 7:20










  • @Disaffected1070452 can you give me any example so i can do it by myself?
    – Beeman
    Nov 13 '18 at 7:36








1




1




If you learn about data binding, updating the DB is a single simple method myDataAdapter.Update();
– WelcomeOverflow
Nov 13 '18 at 7:20




If you learn about data binding, updating the DB is a single simple method myDataAdapter.Update();
– WelcomeOverflow
Nov 13 '18 at 7:20












@Disaffected1070452 can you give me any example so i can do it by myself?
– Beeman
Nov 13 '18 at 7:36




@Disaffected1070452 can you give me any example so i can do it by myself?
– Beeman
Nov 13 '18 at 7:36












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274935%2fhow-to-update-datagridview-items-in-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274935%2fhow-to-update-datagridview-items-in-c-sharp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud