正如标题所说,我如何在选择 In-Active 时在组合框中转换说两个字符串值(Active 和 In-Active)增加 iActive 列下数据库列默认值的值从 0 到 1。到目前为止我试过了Convert.Toint32 并将我的存储过程更改为
CREATE
DEFINER=`root`@`localhost`
PROCEDURE `sp_edit_user`
(
pUserID INT(11),
pEmployee_Name VARCHAR(15),
pUser_Name VARCHAR(15),
pRole VARCHAR(15),
piActive INT(1)
)
BEGIN
UPDATE t_user_auth SET Employee_Name = pEmployee_Name, User_Name = pUser_Name, Role = pRole, iActive = piActive + 1
WHERE UserID = pUserID;
END$$
DELIMITER ;
代码是
private void kryptonbtnSaveEdit_Click(object sender, EventArgs e)
{
var connectionString = ConfigurationManager.ConnectionStrings["Pigen"].ConnectionString;
using (MySqlConnection cnn = new MySqlConnection(connectionString))
using (MySqlCommand cmd = cnn.CreateCommand())
{
try
{
cnn.Open();
cmd.CommandText = "sp_edit_user";
cmd.CommandType = CommandType.StoredProcedure;
// MessageBox.Show((comboBox1Status.SelectedValue), "");
cmd.Parameters.AddWithValue("@pUserID", Convert.ToInt64(lbluserID.Text));
cmd.Parameters.AddWithValue("@pEmployee_Name", txtboxEmploy.Text);
cmd.Parameters.AddWithValue("@pUser_Name", txtboxuser.Text);
cmd.Parameters.AddWithValue("@pRole", comboBox2Role.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@piActive", Convert.ToInt32(comboBox1Status.SelectedValue));
//if(comboBox1Status.SelectedText != "Active")
//{
// int m = Int32.Parse("In-Active");
//}
我注意到所有值都从 0 增加到 1,即使选择仍然处于事件状态,这可能来 self 的存储过程 iActive + 1。我该如何编写它以接受 In-Active 作为值 1。
最佳答案
也许你可以通过条件运算符来做到这一点:
cmd.Parameters.AddWithValue("@piActive", ((comboBox1Status.SelectedText == "Active") ? 1 : 0));
如果选择“Active”,这会将 @piActive
设置为 1,否则将 @piActive
设置为 0。
关于c# - 我如何将组合框字符串值转换为整数以在 C# 中解析到 mysql 数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28022769/