这是我表的内容
tbl_range
RID // Primary Key , INT
RangeFrom // Starting Range , DOUBLE
RangeTo // End Range , DOUBLE
EE // Output , DOUBLE
所以我试图执行的查询是
SELECT EE FROM db.tbl_range WHERE RangeFrom <= @GP AND RangeTo >= @GP;
我尝试在sql上运行查询但它有效但在c#中我没有返回任何内容,这里是我的代码
cc.SetCMD("SELECT EE FROM mia_payroll.tbl_sssrange WHERE RangeFrom <= @GP AND RangeTo >= @GP;");
using (myConn = new MySqlConnection(ConnectionClass.GetConnection()))
{
myConn.Open();
using (cmDB = new MySqlCommand(cc.GetCMD(), myConn))
{
cmDB.Parameters.AddWithValue("@GP", GP);
try
{
using (myReader = cmDB.ExecuteReader())
{
while (myReader.Read())
{
ee = myReader.GetOrdinal("EE");
lblEE.Text = System.Convert.ToString(ee);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
myReader.Close();
myConn.Close();
}
}
和GP是用户定义的
答案 0 :(得分:1)
请勿使用GetOrdinal
,请尝试:
while (myReader.Read())
{
lblEE.Text = myReader[0].ToString();
}
答案 1 :(得分:1)
您的逻辑错误,GP必须在范围内
SELECT EE FROM db.tbl_range WHERE @GP BETWEEN RangeFrom AND RangeTo;