小编Per*_*ist的帖子

十进制到字符串"指定的强制转换无效"

private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
    SqlCommand cmd = new SqlCommand(@"Select * FROM PRODUCTS where [PRODUCT CODE] = '" + comboBox4.Text + "'", con);
    SqlDataReader myReader;
    try
    {
        con.Open();
        myReader = cmd.ExecuteReader();

        while (myReader.Read())
        {
            int decimPRICE = myReader.GetInt32(myReader.GetOrdinal("PRICE"));
            string PRICE = decimPRICE.ToString("0.00");
            textBox7.Text = PRICE;

        }
        con.Close();
    }
    catch (Exception exe)
    {
        MessageBox.Show(exe.Message);
    }
}
Run Code Online (Sandbox Code Playgroud)

它在ComboBoxTextbox中

此代码没问题,但是当我在ComboBox中单击项目/索引时出现" 指定的强制转换无效 " .我不知道为什么.

decimPRICE是PRICE(十进制18,2).

c# combobox textbox

1
推荐指数
1
解决办法
772
查看次数

标签 统计

c# ×1

combobox ×1

textbox ×1