How to Query multiple tables dynamically VB.NET -


I have 30 different tables in my database for each table the same column name "res_ret" = defined I want to update the code in every table > 0 and set the res_ret value = 1 . This is my code and it is work. Thanks in advance how can I do this in dynamic code :)

  conn.Open () SQL = "update set table_1 res_ret = 1" cmd.CommandText = SQL cmd.Connection = Conn cmd .ExecuteNonQuery () SQL = "update table_2 set res_ret = 1" cmd.CommandText = SQL cmd.Connection = Conn cmd.ExecuteNonQuery () SQL = "update set table_3 res_ret = 1" cmd.CommandText = SQL cmd.Connection = Conn cmd .ExecuteNonQuery () that conn.Dispose () Conn.Close ()  

as @ Timshaimtr's is said, perhaps a better way of doing this, but:

VB.NET

  dim tableList = {"table_1", "table_2", "table_3"} for each tableName string in the tableList cmd .commandText = String.Format ("update {0} set res_ret = 1", TableName) cmd.ExecuteNonQuery () Next  

c #

  var tableList = new list & lt; String & gt; {"Table_1", "table_2", "table_3" ...}; foreach (var TableName in tableList) {cmd.CommandText = String.Format ( "Update {0} set res_ret = 1", TableName); Cmd.ExecuteNonQuery (); }  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -