How to sum datagridview contents to database VB.net multiple users












0















How can I sum the contents of my datagridview on my database. i have a code shown, however it just updates not sum.



So here is my code on save:



Public Sub save_dgv()
Try
con.Close()
con.Open()
Dim scb = New MySqlCommandBuilder(SDA)
SDA.Update(dbDataset)
MessageBox.Show("Submitted!")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


sample:

user1
id--row1--row2--total
1 --25 -- 23 --48

user2
id--row1--row2--total
1 --25 -- 23 --48

output
id--row1--row2--total
1 --50-- 46--96









share|improve this question

























  • "what I want to happen is when user 1 submits, then user 2 submits, the values just ADD(+) not update. " Sounds like a race condition..

    – Raymond Nijland
    Nov 19 '18 at 13:20













  • Could you clarify a little? Maybe show some sample output of what you would like to see happen? For some reason I read this 3-4 times and either your question is going right over my head or it's not worded well.

    – haag1
    Nov 19 '18 at 13:21











  • Edited.. should I use separate table for each user? then add using sql?

    – TakeAcake
    Nov 19 '18 at 13:25











  • a separate database table for each user? No. Don't even think about it. But anyway it's not clear what the issue really is - are you asking how to add new rows to your database? As haag1 says, please give a clear indication of the scenario - add some more code if necessary so we can understand what is happening with your gridview

    – ADyson
    Nov 19 '18 at 13:51











  • I wanted to merge the input from user1 and user2 into 1 table. not change the values. :(

    – TakeAcake
    Nov 19 '18 at 13:55
















0















How can I sum the contents of my datagridview on my database. i have a code shown, however it just updates not sum.



So here is my code on save:



Public Sub save_dgv()
Try
con.Close()
con.Open()
Dim scb = New MySqlCommandBuilder(SDA)
SDA.Update(dbDataset)
MessageBox.Show("Submitted!")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


sample:

user1
id--row1--row2--total
1 --25 -- 23 --48

user2
id--row1--row2--total
1 --25 -- 23 --48

output
id--row1--row2--total
1 --50-- 46--96









share|improve this question

























  • "what I want to happen is when user 1 submits, then user 2 submits, the values just ADD(+) not update. " Sounds like a race condition..

    – Raymond Nijland
    Nov 19 '18 at 13:20













  • Could you clarify a little? Maybe show some sample output of what you would like to see happen? For some reason I read this 3-4 times and either your question is going right over my head or it's not worded well.

    – haag1
    Nov 19 '18 at 13:21











  • Edited.. should I use separate table for each user? then add using sql?

    – TakeAcake
    Nov 19 '18 at 13:25











  • a separate database table for each user? No. Don't even think about it. But anyway it's not clear what the issue really is - are you asking how to add new rows to your database? As haag1 says, please give a clear indication of the scenario - add some more code if necessary so we can understand what is happening with your gridview

    – ADyson
    Nov 19 '18 at 13:51











  • I wanted to merge the input from user1 and user2 into 1 table. not change the values. :(

    – TakeAcake
    Nov 19 '18 at 13:55














0












0








0








How can I sum the contents of my datagridview on my database. i have a code shown, however it just updates not sum.



So here is my code on save:



Public Sub save_dgv()
Try
con.Close()
con.Open()
Dim scb = New MySqlCommandBuilder(SDA)
SDA.Update(dbDataset)
MessageBox.Show("Submitted!")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


sample:

user1
id--row1--row2--total
1 --25 -- 23 --48

user2
id--row1--row2--total
1 --25 -- 23 --48

output
id--row1--row2--total
1 --50-- 46--96









share|improve this question
















How can I sum the contents of my datagridview on my database. i have a code shown, however it just updates not sum.



So here is my code on save:



Public Sub save_dgv()
Try
con.Close()
con.Open()
Dim scb = New MySqlCommandBuilder(SDA)
SDA.Update(dbDataset)
MessageBox.Show("Submitted!")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


sample:

user1
id--row1--row2--total
1 --25 -- 23 --48

user2
id--row1--row2--total
1 --25 -- 23 --48

output
id--row1--row2--total
1 --50-- 46--96






mysql .net vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 14:09







TakeAcake

















asked Nov 19 '18 at 13:17









TakeAcakeTakeAcake

32




32













  • "what I want to happen is when user 1 submits, then user 2 submits, the values just ADD(+) not update. " Sounds like a race condition..

    – Raymond Nijland
    Nov 19 '18 at 13:20













  • Could you clarify a little? Maybe show some sample output of what you would like to see happen? For some reason I read this 3-4 times and either your question is going right over my head or it's not worded well.

    – haag1
    Nov 19 '18 at 13:21











  • Edited.. should I use separate table for each user? then add using sql?

    – TakeAcake
    Nov 19 '18 at 13:25











  • a separate database table for each user? No. Don't even think about it. But anyway it's not clear what the issue really is - are you asking how to add new rows to your database? As haag1 says, please give a clear indication of the scenario - add some more code if necessary so we can understand what is happening with your gridview

    – ADyson
    Nov 19 '18 at 13:51











  • I wanted to merge the input from user1 and user2 into 1 table. not change the values. :(

    – TakeAcake
    Nov 19 '18 at 13:55



















  • "what I want to happen is when user 1 submits, then user 2 submits, the values just ADD(+) not update. " Sounds like a race condition..

    – Raymond Nijland
    Nov 19 '18 at 13:20













  • Could you clarify a little? Maybe show some sample output of what you would like to see happen? For some reason I read this 3-4 times and either your question is going right over my head or it's not worded well.

    – haag1
    Nov 19 '18 at 13:21











  • Edited.. should I use separate table for each user? then add using sql?

    – TakeAcake
    Nov 19 '18 at 13:25











  • a separate database table for each user? No. Don't even think about it. But anyway it's not clear what the issue really is - are you asking how to add new rows to your database? As haag1 says, please give a clear indication of the scenario - add some more code if necessary so we can understand what is happening with your gridview

    – ADyson
    Nov 19 '18 at 13:51











  • I wanted to merge the input from user1 and user2 into 1 table. not change the values. :(

    – TakeAcake
    Nov 19 '18 at 13:55

















"what I want to happen is when user 1 submits, then user 2 submits, the values just ADD(+) not update. " Sounds like a race condition..

– Raymond Nijland
Nov 19 '18 at 13:20







"what I want to happen is when user 1 submits, then user 2 submits, the values just ADD(+) not update. " Sounds like a race condition..

– Raymond Nijland
Nov 19 '18 at 13:20















Could you clarify a little? Maybe show some sample output of what you would like to see happen? For some reason I read this 3-4 times and either your question is going right over my head or it's not worded well.

– haag1
Nov 19 '18 at 13:21





Could you clarify a little? Maybe show some sample output of what you would like to see happen? For some reason I read this 3-4 times and either your question is going right over my head or it's not worded well.

– haag1
Nov 19 '18 at 13:21













Edited.. should I use separate table for each user? then add using sql?

– TakeAcake
Nov 19 '18 at 13:25





Edited.. should I use separate table for each user? then add using sql?

– TakeAcake
Nov 19 '18 at 13:25













a separate database table for each user? No. Don't even think about it. But anyway it's not clear what the issue really is - are you asking how to add new rows to your database? As haag1 says, please give a clear indication of the scenario - add some more code if necessary so we can understand what is happening with your gridview

– ADyson
Nov 19 '18 at 13:51





a separate database table for each user? No. Don't even think about it. But anyway it's not clear what the issue really is - are you asking how to add new rows to your database? As haag1 says, please give a clear indication of the scenario - add some more code if necessary so we can understand what is happening with your gridview

– ADyson
Nov 19 '18 at 13:51













I wanted to merge the input from user1 and user2 into 1 table. not change the values. :(

– TakeAcake
Nov 19 '18 at 13:55





I wanted to merge the input from user1 and user2 into 1 table. not change the values. :(

– TakeAcake
Nov 19 '18 at 13:55












1 Answer
1






active

oldest

votes


















0














Try the following. Adjust data types to your db. Works in SQL Server but not tested in MySQL.



Using cn As New MySqlConnection("Your connection string")
Dim s As String = "Update MyTable Set row1 = row1 + @row1, row2 = row2 + @row2 where id = @id"
Using cmd As New MySqlCommand(s, cn)
cmd.Parameters.Add("@row1", MySqlDbType.Int32).Value = intRow1
cmd.Parameters.Add("@row2", MySqlDbType.Int32).Value = intRow2
cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = intID
cn.Open()
cmd.ExecuteNonQuery()
End Using
End Using





share|improve this answer
























  • I'll be trying this tonight. I will update you if successful! :D Thanks so much!

    – TakeAcake
    Nov 21 '18 at 2:59











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%2f53375499%2fhow-to-sum-datagridview-contents-to-database-vb-net-multiple-users%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try the following. Adjust data types to your db. Works in SQL Server but not tested in MySQL.



Using cn As New MySqlConnection("Your connection string")
Dim s As String = "Update MyTable Set row1 = row1 + @row1, row2 = row2 + @row2 where id = @id"
Using cmd As New MySqlCommand(s, cn)
cmd.Parameters.Add("@row1", MySqlDbType.Int32).Value = intRow1
cmd.Parameters.Add("@row2", MySqlDbType.Int32).Value = intRow2
cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = intID
cn.Open()
cmd.ExecuteNonQuery()
End Using
End Using





share|improve this answer
























  • I'll be trying this tonight. I will update you if successful! :D Thanks so much!

    – TakeAcake
    Nov 21 '18 at 2:59
















0














Try the following. Adjust data types to your db. Works in SQL Server but not tested in MySQL.



Using cn As New MySqlConnection("Your connection string")
Dim s As String = "Update MyTable Set row1 = row1 + @row1, row2 = row2 + @row2 where id = @id"
Using cmd As New MySqlCommand(s, cn)
cmd.Parameters.Add("@row1", MySqlDbType.Int32).Value = intRow1
cmd.Parameters.Add("@row2", MySqlDbType.Int32).Value = intRow2
cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = intID
cn.Open()
cmd.ExecuteNonQuery()
End Using
End Using





share|improve this answer
























  • I'll be trying this tonight. I will update you if successful! :D Thanks so much!

    – TakeAcake
    Nov 21 '18 at 2:59














0












0








0







Try the following. Adjust data types to your db. Works in SQL Server but not tested in MySQL.



Using cn As New MySqlConnection("Your connection string")
Dim s As String = "Update MyTable Set row1 = row1 + @row1, row2 = row2 + @row2 where id = @id"
Using cmd As New MySqlCommand(s, cn)
cmd.Parameters.Add("@row1", MySqlDbType.Int32).Value = intRow1
cmd.Parameters.Add("@row2", MySqlDbType.Int32).Value = intRow2
cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = intID
cn.Open()
cmd.ExecuteNonQuery()
End Using
End Using





share|improve this answer













Try the following. Adjust data types to your db. Works in SQL Server but not tested in MySQL.



Using cn As New MySqlConnection("Your connection string")
Dim s As String = "Update MyTable Set row1 = row1 + @row1, row2 = row2 + @row2 where id = @id"
Using cmd As New MySqlCommand(s, cn)
cmd.Parameters.Add("@row1", MySqlDbType.Int32).Value = intRow1
cmd.Parameters.Add("@row2", MySqlDbType.Int32).Value = intRow2
cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = intID
cn.Open()
cmd.ExecuteNonQuery()
End Using
End Using






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 20:52









MaryMary

3,5012819




3,5012819













  • I'll be trying this tonight. I will update you if successful! :D Thanks so much!

    – TakeAcake
    Nov 21 '18 at 2:59



















  • I'll be trying this tonight. I will update you if successful! :D Thanks so much!

    – TakeAcake
    Nov 21 '18 at 2:59

















I'll be trying this tonight. I will update you if successful! :D Thanks so much!

– TakeAcake
Nov 21 '18 at 2:59





I'll be trying this tonight. I will update you if successful! :D Thanks so much!

– TakeAcake
Nov 21 '18 at 2:59




















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%2f53375499%2fhow-to-sum-datagridview-contents-to-database-vb-net-multiple-users%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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()