Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8003999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:48:04+00:00 2026-06-04T16:48:04+00:00

I split the command over several lines for ease of editing: string docommand =

  • 0

I split the command over several lines for ease of editing:

string docommand = "";
docommand += "DROP TABLE IF EXISTS `config`;";
//docommand += "/*!40101 SET @saved_cs_client     = @@character_set_client */;";
//docommand += "/*!40101 SET character_set_client = utf8 */;";
docommand += "CREATE TABLE `config` (";
docommand += "  `name` varchar(200) NOT NULL,";
docommand += "  `value` varchar(200) NOT NULL,";
docommand += "  `timestamp` int(11) NOT NULL,";
docommand += "  UNIQUE KEY `name` (`name`)";
docommand += ")";
//docommand += " ENGINE=MyISAM DEFAULT CHARSET=latin1";
docommand += ";";
//docommand += "/*!40101 SET character_set_client = @saved_cs_client */;";

mysql_connect connect = new mysql_connect();
MySqlConnection conn = connect.connect(core_config.server, core_config.database, core_config.username, core_config.pass);
bool success = mysql_command.command(docommand, conn);
connect.disconnect();

if (!success)
    Console.WriteLine("Command failed : " + docommand);

As you can see I commented out a few lines to see if they were causing trouble. Didn’t make a difference.

Output:

Returning false because resultSet is 0
Command failed : DROP TABLE IF EXISTS `config`;CREATE TABLE `config` (  `name` varchar(200) NOT NULL,  `value` varchar(200) NOT NULL,  `timestamp` int(11) NOT NULL,  UNIQUE KEY `name` (`name`));

But the table is correctly created… and when I paste the exact same command in phpmyadmin and run it from there, it reports no problems whatsoever.

A command like "SELECT * FROM config" does not report a failure. So why does the CREATE TABLE command do?

mysql_command.command() function:

public static bool command(string input, MySqlConnection con)
{
    try
    {
        MySqlCommand command = new MySqlCommand(input, con);
        var resultSet = command.ExecuteNonQuery();

        if (!resultSet.Equals(0))
        {
            return true;
        }
        Console.WriteLine("Returning false because resultSet is 0");
        return false;
    }
    catch (Exception ex) { Console.WriteLine("MySQL command error : "+ex.Message); }
    Console.WriteLine("Returning false after exception");
    return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:48:04+00:00Added an answer on June 4, 2026 at 4:48 pm

    Both DROP TABLE and CREATE TABLE do not send back anything other than 0. Therefore your “command” method will always believe the command fails. The ExecuteNonQuery() will returns the rows affected by your statements, which will be 0.

    What you could do, in pass in the amount of rows you expect it to change, so something like:

    public static bool command(string input, MySqlConnection con, int expectedRowsAffected = 0)
    {
    try
    {
        MySqlCommand command = new MySqlCommand(input, con);
        var resultSet = command.ExecuteNonQuery();
    
        if (resultSet.Equals(expectedRowsAffected))
        {
            return true;
        }
        Console.WriteLine(string.Format("Returning false because resultSet isn't {0}", expectedRowsAffected));
        return false;
    }
    catch (Exception ex) 
    { 
        Console.WriteLine("MySQL command error : "+ex.Message); 
    }
    Console.WriteLine("Returning false after exception");
    return false;
    

    }

    This is not a great way of doing it – as I said, whether or not a command is “successful” can mean different things – but at a low level, a command is successful if it runs without any errors/exceptions, which you are already checking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to split a PowerShell command line over multiple lines? In Visual
I am trying to spread one sed command over several lines in a bash
public class Command { public int CommandId { get; set; } public string Title
I got problem with using split command. The input string is as follows: 080821_HWI-EAS301_0002_30ALBAAXX:1:8:1649:2027
I want to split a string suppressing all null fields Command: ,1,2,,3,4,,.split(',') Result: [,
How can I split long commands over multiple lines in a batch file?
I want to split a command line like string in single string parameters. How
I'm using the split linux command to split huge xml files into node-sized ones.
How do you take a command like the following in PowerShell and split it
I have a class I use to split a string of SQL commands by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.