存储过程以将所有数据插入数据库,包括下拉列表 [英] store procedure to insret all the data into database including dropdownlist

查看:72
本文介绍了存储过程以将所有数据插入数据库,包括下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储程序将所有数据插入数据库,包括下拉列表,





textbox1 =

textbox2 =

dropdownlist = add / summul / div

result =



所有将存储在数据库中商店程序



喜欢

首先没有秒没有操作结果

store procedure to insert all the data into database including dropdown list,


textbox1=
textbox2=
dropdownlist=add/summul/div
result=

all will be store in database using store procedure

like
first no second no operation result

推荐答案

做一件事

创建程序只需4个参数 textbox1,textbox2,下拉列表使用varchar(max)和结果。

< dropdownlist中的
传递在下拉列表中选择的逗号分隔值。



在存储过程中写入逻辑以拆分该下拉列表字符串并执行插入工作。
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();

}
}
}


这篇关于存储过程以将所有数据插入数据库,包括下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆