Reputation: 3
I need to add this command.CommandText
result to command2.CommandText
instead "result"
string connString = "connect data;";
MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand command = conn.CreateCommand();
MySqlCommand command1 = conn.CreateCommand();
MySqlCommand command2 = conn.CreateCommand();
command.CommandText = "SELECT `order_id` FROM `test` WHERE `order_item_type`='line_item' AND `order_offer_send`='0';";
command2.CommandText = "SELECT `meta_value` FROM `test1` WHERE `order_item_id`='" + result + "'";
Upvotes: 0
Views: 86
Reputation: 45947
i would work with parameters to avoid SQL Injection attacks and using directive to avoid open connections and a better usage of the gc:
string connString = "connect data;";
string Command = "SELECT `order_id` FROM `test` WHERE `order_item_type`='line_item' AND `order_offer_send`= @order_offer_send limit 1;";
string Command2 = "SELECT `meta_value` FROM `test1` WHERE `order_item_id`= @result limit 1";
int OfferID = -1;
string meta_value = null;
using (MySqlConnection mConnection = new MySqlConnection(connString))
{
mConnection.Open();
using (MySqlCommand myCmd = new MySqlCommand(Command, mConnection))
{
myCmd.Parameters.Add(new MySqlParameter("@order_offer_send", "0"));
OfferID = (int)myCmd.ExecuteScalar();
}
using (MySqlCommand myCmd = new MySqlCommand(Command2, mConnection))
{
myCmd.Parameters.Add(new MySqlParameter("@result", OfferID));
meta_value = (string)myCmd.ExecuteScalar();
}
}
Upvotes: 1