[英]how do i convert combobox string values to integer to be parsed into mysql database in c#
as the heading says how do i convert say two string values (Active and In-Active) in a combobox upon selection of In-Active increases value of database column default value under column iActive from 0 to 1. so far i tried Convert.Toint32 and changed my stored procedure as 如标题所示我如何转换说组合框中的两个字符串值(活动和非活动)选择In-Active时,从0到1列iActive下的数据库列默认值的值增加到目前为止我尝试了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 ;
and code is 和代码是
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");
//}
what i notice is all values are increased from 0 to 1 even if selection is still on Active, probably from my stored procedure iActive + 1. how do i write this to accept In-Active as value 1. 我注意到所有值都从0增加到1,即使选择仍处于活动状态,可能来自我的存储过程iActive + 1.我如何编写此接受In-Active作为值1。
Probably you can do this by conditional operator : 可能你可以通过条件运算符来做到这一点:
cmd.Parameters.AddWithValue("@piActive", ((comboBox1Status.SelectedText == "Active") ? 1 : 0));
This will set @piActive
as 1 if "Active" is selected else set @piActive
as 0. 如果选择“Active”,则将@piActive
设置为1,否则将@piActive
设置为0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.