我有以下查询
SELECT count( * ) COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = 'ptbs.ms_karyawan'
并在 mysql wamp 上执行它们,它返回 2 列
但是,当我使用 C# 执行上面的查询时,它返回 -1 列,这是代码
private void button1_Click(object sender, EventArgs e)
{
int table = dbc.Count("ptbs.ms_karyawan");
msg.Sukses("Jumlah table adalah :"+table, "Login");
}
这是dbc.count()
代码
public int Count(string table_name)
{
string query = "SELECT count( * ) COLUMN_NAME FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '"+table_name+"'";
int table = 0;
if (OpenConnection() == true)
{
//create mysql command
MySqlCommand cmd = new MySqlCommand();
//Assign the query using CommandText
cmd.CommandText = query;
//Assign the connection using Connection
cmd.Connection = connection;
//Execute query
table = cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
return table;
}
为什么他们返回不同的值,虽然我使用相同的查询?我做错了什么 ?