更新时间:2023-02-10 12:58:04
做一件事
创建程序只需4个参数即 textbox1,textbox2,下拉列表使用varchar(max)和结果。
传递在下拉列表中选择的逗号分隔值。
在存储过程中写入逻辑以拆分该下拉列表字符串并执行插入工作。
Do one thing
create procedure that will take only 4 parameters i.e. textbox1, textbox2, for dropdownlist use varchar(max) and result.
in dropdownlist passs comma separated values which are selected in dropdownlist.
Write logic in stored procedure for spliting that dropdownlist string and do insertion work.
数据没有存储在数据库中
the data is not storing inside the database
protected void Button1_Click(object sender,EventArgs e)
{
SqlConnect ion con = new SqlConnection(Data Source = .; Initial Catalog = demo1; Integrated Security = True);
con.Open();
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text );
if(DropDownList1.Text ==add)
{
int sum =(a + b);
Label1.Text = Convert.ToString(sum);
dat.Text = DateTime.Now.ToString( );
}
如果
(DropDownList1.Text == sub)
{
int sub =(a - b);
Label1.Text = Convert.ToString(sub);
dat.Text = DateTime.Now.ToString();
}
如果
(DropDownList1.Text = =m ul)
{
int mul = a * b;
Label1.Text = Convert.ToString(mul);
dat.Text = DateTime.Now.ToString();
}
如果
(DropDownList1.Text ==div )
{
十进制div = a / b;
Label1.Text = Convert.ToString(div);
dat.Text = DateTime.Now.ToString();
}
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText =p;
cmd.Parameters.AddWithValue(@ firsttno,TextBox1.Text);
cmd.Parameters.AddWithValue(@ secondno,TextBox2.Text);
cmd.Parameters.AddWithValue(@ operation, DropDownList1.Text);
cmd.Parameters.AddWithValue(@ result,Label1.Text);
cmd.Parameters.AddWithValue(@ optime,dat。文字);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close ();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=demo1;Integrated Security=True");
con.Open();
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text);
if (DropDownList1.Text == "add")
{
int sum = (a + b);
Label1.Text = Convert.ToString(sum);
dat.Text = DateTime.Now.ToString();
}
if
(DropDownList1.Text == "sub")
{
int sub = (a - b);
Label1.Text = Convert.ToString(sub);
dat.Text = DateTime.Now.ToString();
}
if
(DropDownList1.Text == "mul")
{
int mul = a * b;
Label1.Text = Convert.ToString(mul);
dat.Text = DateTime.Now.ToString();
}
if
(DropDownList1.Text == "div")
{
decimal div = a / b;
Label1.Text = Convert.ToString(div);
dat.Text = DateTime.Now.ToString();
}
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "p";
cmd.Parameters.AddWithValue("@firsttno", TextBox1.Text);
cmd.Parameters.AddWithValue("@secondno", TextBox2.Text);
cmd.Parameters.AddWithValue("@operation", DropDownList1.Text);
cmd.Parameters.AddWithValue("@result", Label1.Text);
cmd.Parameters.AddWithValue("@optime", dat.Text);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
}
}
}