Home > Software engineering >  VB.net connection MySQL query many times must the NEW every time a MySqlCommand?
VB.net connection MySQL query many times must the NEW every time a MySqlCommand?

Time:11-30

Connection is global, even can be used directly, but can't use the existing MySqlCommand to perform new query?
For example:
CMD=New MySqlCommand (cmdstr1, conn), can return to a query result cmdstr1
If I want to perform cmdstr2 query, it is necessary to CMD=New MySqlCommand (cmdstr2, conn) to create a New instance?
This new takes up too much memory, under the condition of multiple queries memory just came up
MySqlCommand function have provide query function?

CodePudding user response:

You can try to modify the MySqlCommand object in the query string

CodePudding user response:

Don't need a New, MySqlCommand objects are generally not reuse,
MySqlCommand have a property called CommandText, every time the query, the SQL statement is assigned to this property, then execute ExecuteXXXX method (ExecuteNonQuery returns affect the number of records, can use the MySqlDataAdapter will result the Fill to a DataSet; ExecuteScalar can also be used to take the first record of the first field value)
  • Related