当前位置: 移动技术网 > IT编程>开发语言>.net > 用存储过程向数据库存值的具体实现

用存储过程向数据库存值的具体实现

2017年12月12日  | 移动技术网IT编程  | 我要评论
cs文件中的代码
复制代码 代码如下:

//收看视频三个标准
//从页面传参数过来
int v1_biaozhou = convert.toint32(textbox1.text);
int v1_feizhi= convert.toint32(textbox4.text);

int v2_biaozhou = convert.toint32(textbox2.text);
int v2_feizhi= convert.toint32(textbox5.text);

int v3_biaozhou = convert.toint32(textbox3.text);
int v3_feizhi= convert.toint32(textbox6.text);

//作业批阅数(篇)
int z1_biaozhun=convert .toint32 (textbox7 .text );
int z1_feizhi=convert .toint32 (textbox10 .text );

int z2_biaozhun=convert .toint32 (textbox8 .text );
int z2_feizhi=convert .toint32 (textbox11 .text );

int z3_biaozhun=convert .toint32 (textbox9 .text );
int z3_feizhi=convert .toint32 (textbox12 .text );

//实例化对象(learning库对应的是edboperation)
edb=new edboperation();
//使用存储过程
string procname="insert_update_project_standard";
//插入数据
sqlparameter[] spp=new sqlparameter[]{
new sqlparameter("@project_id",projectid),
new sqlparameter("@v1_biaozhou",v1_biaozhou),
new sqlparameter ("@v1_fengzhi",v1_feizhi),
new sqlparameter ("@v2_biaozhou",v2_biaozhou),
new sqlparameter ("@v2_fengzhi",v2_feizhi),
new sqlparameter ("@v3_biaozhou",v3_biaozhou),
new sqlparameter ("@v3_fengzhi",v3_feizhi),
new sqlparameter ("@z1_biaozhun",z1_biaozhun),
new sqlparameter ("@z1_fenzhi",z1_feizhi),
new sqlparameter ("@z2_biaozhun",z2_biaozhun),
new sqlparameter ("@z2_fenzhi",z2_feizhi),
new sqlparameter ("@z3_biaozhun",z3_biaozhun),
new sqlparameter ("@z3_fenzhi",z3_feizhi)

};

new sqlparameter ("数据库存储过程中的字段名",定义的字段名)
aspx中的代码
复制代码 代码如下:

<tr>
<td style="width: 101px; text-align: center;">
<asp:label id="label2" runat="server" text="收看视频(分钟):" font-size="9pt" width="132px"></asp:label>
</td>
<td style="text-align: left;"colspan="2">
<table>
<tr style="height:25px;">
<td style="width:180px;"><asp:textbox id="textbox1" runat="server"></asp:textbox></td>
<td style="width:180px;"><asp:textbox id="textbox4" runat="server"></asp:textbox></td>
</tr>

<tr>
<td class="auto-style3"><asp:textbox id="textbox2" runat="server"></asp:textbox></td>
<td class="auto-style3"><asp:textbox id="textbox5" runat="server"></asp:textbox></td>
</tr>

<tr style="height:25px;">
<td style="width:180px;"><asp:textbox id="textbox3" runat="server" ontextchanged="textbox3_textchanged"></asp:textbox></td>
<td style="width:180px;"><asp:textbox id="textbox6" runat="server"></asp:textbox></td>
</tr>

</table>

</td>
</tr>
<tr>
<td style="width: 101px; text-align: center;">
<asp:label id="labele" runat="server" text="作业批阅数(篇):" font-size="9pt" width="132px"></asp:label>
</td>
<td style="text-align: left;"colspan="2">
<table>
<tr style="height:25px;">
<td style="width:180px;"><asp:textbox id="textbox7" runat="server"></asp:textbox></td>
<td style="width:180px;"><asp:textbox id="textbox10" runat="server"></asp:textbox></td>
</tr>

<tr style="height:25px;">
<td style="width:180px;"><asp:textbox id="textbox8" runat="server"></asp:textbox></td>
<td style="width:180px;"><asp:textbox id="textbox11" runat="server"></asp:textbox></td>
</tr>

<tr style="height:25px;">
<td style="width:180px;"><asp:textbox id="textbox9" runat="server"></asp:textbox></td>
<td style="width:180px;"><asp:textbox id="textbox12" runat="server"></asp:textbox></td>
</tr>

存储过程
复制代码 代码如下:

//创建存储过程

create proc insert_update_project_standard
@project_id int,
@v1_biaozhou int,
@v1_fengzhi int,
@v2_biaozhou int,
@v2_fengzhi int,
@v3_biaozhou int,
@v3_fengzhi int,
@z1_biaozhun int,
@z1_fenzhi int,
@z2_biaozhun int,
@z2_fenzhi int,
@z3_biaozhun int,
@z3_fenzhi int
as

//像存储过程中对应着插入数据

insert into t_learning_project_standard(sid,khbz,fz) values(@project_id,@v1_biaozhou,@v1_fengzhi)

insert into t_learning_project_standard(sid,khbz,fz) values(@project_id,@v2_biaozhou,@v2_fengzhi)
insert into t_learning_project_standard(sid,khbz,fz) values(@project_id,@v3_biaozhou,@v3_fengzhi)

insert into t_learning_project_standard (sid ,khbz ,fz )values(@project_id ,@z1_biaozhun ,@z1_fenzhi )
insert into t_learning_project_standard(sid ,khbz ,fz )values(@project_id ,@z2_biaozhun ,@z2_fenzhi )
insert into t_learning_project_standard (sid ,khbz ,fz )values(@project_id ,@z3_biaozhun ,@z3_fenzhi )

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网