例如,我桌上的My Item_Quantity为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();
}
我希望有人可以帮助我:(
答案 0 :(得分:0)
这就是我想要发生的事情:示例:数据库:Item_Quantity = 50,我想将NumericUpDown的最大值设置为Item_Quantity的值:(
据我了解,您不知道如何获得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
}