Click here to Skip to main content
15,867,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, how to update three tables do not duplicating query?

SQL
ds = New DataSet
da = New MySqlDataAdapter("update youtube set views=views-1, clicks=clicks+1, today_clicks=today_clicks+1 where id ='" & lvDisplay.Items(0).SubItems(1).Text & "'", sqlcon)
da.Fill(ds, "youtube")
ds = New DataSet
da = New MySqlDataAdapter("update users set coins=coins+'" & Label22.Text & "' where id='" & ListView2.Items(0).SubItems(0).Text & "'", sqlcon)
da.Fill(ds, "users")
ds = New DataSet
da = New MySqlDataAdapter("update web_stats set value=value+1 Where `module_id` = 'youtube'", sqlcon)
da.Fill(ds, "web_stats")
Posted

To update data, you need to call MySQLCommand.ExecuteNonQuery[^] method, than load it again.
 
Share this answer
 
I was thinking you could do it through a view - but, a view can only modify one tablre as far as I can see in a quick trawl through the docco

I don't think you can avoid the multiple insert, but, I'd suggest you move the logic to a stored procedure
 
Share this answer
 
SQL UPDATE command designed to update one and only one table at one time - it's a design decision and can not be changed for now...
 
Share this answer
 
Your Code should be like this..

C#
MySqlCommand   cmd1,cmd2,cmd3;

cmd1=New MySQlCommand("update youtube set views=views1,clicks=clicks+1,today_clicks=today_clicks+1 where id ='" & lvDisplay.Items(0).SubItems(1).Text & "'", sqlcon);

cmd1.ExecuteNonQuery();

cmd2 = New MySQlCommand("update users set coins=coins+'" & Label22.Text & "' where id='" & ListView2.Items(0).SubItems(0).Text & "'", sqlcon);

cmd2.ExecuteNonQuery();

cmd3 = New MySQlCommand("update web_stats set value=value+1 Where `module_id` = 'youtube'", sqlcon)
cmd3.ExecuteNonQuery();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900