[C#] Switch Method
#2


string _sql2 = @"SELECT * FROM t_magic a_damagetype WHERE a_name =" + "'" + _Index + "'";
string result1 = Convert.ToString(insertCommand2.ExecuteScalar());

 

25.2.3.1.9. ExecuteScalar

 

Executes the query, and returns the first column of the first row in the result set returned by the query. Extra columns or rows are ignored.

 

Returns: The first column of the first row in the result set, or a null reference if the result set is empty

2

 

 

The problem is because u do select * from t_magic, and the first column is a_index

 

 

MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;

cmd.CommandText = "SELECT a_damagetype FROM t_magic WHERE a_name = @name";
cmd.Prepare();

cmd.Parameters.AddWithValue("@name", _Index);

object res = cmd.ExecuteScalar();

if( res != null )
{
int damageType = Convert.ToInt32(res);

switch(damageType)
{
case 0:
DamageTyp.Text = "No Damage";
break;

case 1:
DamageTyp.Text = "Normal Damage";
break;

case 2:
DamageTyp.Text = "Damage in %";
break;

case 60: // 60 is the Index of a skill! i cheked if i fail!
DamageTyp.Text = "You Fail!";
break;

}
}
else
MessageBox.Show(string.Format("Not found magic : {0}", _Index));



Messages In This Thread
[No subject] - by Nikolee - 09-25-2012, 08:16 PM
[No subject] - by Wizatek - 09-25-2012, 11:37 PM
[No subject] - by HateMe - 09-25-2012, 11:46 PM
[No subject] - by Nikolee - 09-26-2012, 12:24 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)