如何在数据库上设置我的 NumericUpDown

How to set my NumericUpDown on Database

例如,我的 Item_Quantity 在我的 Table 上是 50, 那么我的 NumericUpDown 的最小值将是 1 和 50? 我正在使用 C# 和 MySQL,但无法正常工作。

编辑:

这是我的代码:

string MyConnectionString = "Server=localhost;Port=3307;database=invpos;Uid=root;Pwd=''";

    public void LoadGrid()
    {
        MySqlConnection connection = new MySqlConnection(MyConnectionString);
        connection.Open();

        try
        {
            MySqlCommand cmd = connection.CreateCommand();
            cmd.CommandText = "Select * from items";
            MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adap.Fill(ds);
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            if (connection.State == ConnectionState.Open)
            {
                connection.Clone();
            }
        }
    }

    public void ComboBox()
    {
        MySqlConnection connection = new MySqlConnection(MyConnectionString);
        connection.Open();        
        MySqlCommand cmd = connection.CreateCommand();
        MySqlDataAdapter adap = new MySqlDataAdapter("Select Item_Name from items", connection);
        DataSet ds = new DataSet();
        adap.Fill(ds);
        comboBox1.DataSource = ds.Tables[0];
        comboBox1.DisplayMember = "Item_Name";
    }     
    private void Form4_Load(object sender, EventArgs e)
    {
        LoadGrid();
        ComboBox();

    }

我希望有人能帮助我:(

This is what I want to happen: Example: Database: Item_Quantity = 50 and I want to set my NumericUpDown's Maximum Value into Item_Quantity's value :(

据我了解,您不知道如何获取 NumericUpDown 的最大值?

试试这个:

int itemQuantity = numericUpDown1.Maximum; //Get maximum value of `NumericUpDown`
int currentValue = numericUpdown1.Value; //Get current value of `NumericUpDown`

它能解决您的问题吗?

*更新

try 
{
   MySqlCommand cmd = connection.CreateCommand();
   cmd.CommandText = "Update <your table> set <column> = " + itemQuantity;
   //Use Command Parameter will be better.
   cmd.executeNonQuery(); //execute update.
}
catch (Exception ex)
{
   //Catch exception
}