如何存储转换为带小数点后2位的十进制值

时间:2014-09-24 14:18:50

标签: c# sql winforms datagridview

我从数据库中获取一些数据。我提取的表中有浮点列。我想在numericUpDown控件中显示列的值。因此,我用CAST函数获取这些列;

Connection = new SqlConnection(connectionString);
sdaRecete = new SqlDataAdapter("SELECT ID, Kod, Ad, MalzemeSayisi, Sayilan, Tartilan, CAST(AgirlikNominal as numeric(10, 2)) as 'Nominal Ağırlık', CAST(AgirlikAltDeger as numeric(10, 2)) as 'Ağırlık Alt Limit', CAST(AgirlikUstDeger as numeric(10, 2)) as 'Ağırlık Üst Değer' FROM Recete", connection);
sdaRecete.Fill(dtrecete);
dgvRecipe.DataSource = dtrecete;

问题在于;我想编辑numericUpDown控件的值,而不是将值存储回数据库。为实现这一目标;

private void nudNominalWeight_ValueChanged(object sender, EventArgs e)
        {
            dgvRecipeUpdateSelectedRow(6, nudNominalWeight.Value);
        }

        private void dgvRecipeUpdateSelectedRow(int cellIndex, object value)
        {
            int rowIndex = dgvRecipe.SelectedRows[0].Index;
            object[] items = dtrecete.Rows[rowIndex].ItemArray;
            items[cellIndex] = value;
            dtrecete.Rows[rowIndex].ItemArray = items;
        }

当我点击保存按钮时;

private void tsSaveRecipe_Click(object sender, EventArgs e)
        {
            SqlCommandBuilder scbRecete = new SqlCommandBuilder(sdaRecete);
            sdaRecete.Update(dtrecete);
        }

但代码不起作用。我不能存储这些值。我如何存储这些值?关于我使用CAST功能的问题是什么?

0 个答案:

没有答案