zoukankan
html css js c++ java
个人学习代码保存:例9.在存储过程中使用cast 类型转换的实例
存储过程:
ALTER
PROCEDURE
dbo.GetTitleTop
(
@kindid
int
,
@IntTop
int
)
AS
declare
@sql
varchar
(
200
)
set
@sql
=
'
select top
'
+
cast
(
@IntTop
as
varchar
)
+
'
* from guestbook where kindid=
'
+
cast
(
@kindid
as
varchar
)
EXEC
(
@sql
)
RETURN
前台代码:
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
无标题页
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
KindId:
<
asp:TextBox
ID
="txtKindId"
runat
="server"
></
asp:TextBox
>
<
br
/>
条数:
<
asp:TextBox
ID
="txtIntTop"
runat
="server"
></
asp:TextBox
><
br
/>
<
asp:Button
ID
="Button1"
runat
="server"
Text
="查看"
OnClick
="Button1_Click1"
/>
<
asp:GridView
ID
="GridView1"
runat
="server"
AutoGenerateColumns
="False"
CellPadding
="4"
ForeColor
="#333333"
GridLines
="None"
>
<
FooterStyle
BackColor
="#990000"
Font-Bold
="True"
ForeColor
="White"
/>
<
Columns
>
<
asp:BoundField
DataField
="id"
HeaderText
="序号"
/>
<
asp:BoundField
DataField
="kindId"
HeaderText
="类型编号"
/>
<
asp:BoundField
DataField
="title"
HeaderText
="标题"
/>
<
asp:BoundField
DataField
="body"
HeaderText
="内容"
/>
</
Columns
>
<
RowStyle
BackColor
="#FFFBD6"
ForeColor
="#333333"
/>
<
SelectedRowStyle
BackColor
="#FFCC66"
Font-Bold
="True"
ForeColor
="Navy"
/>
<
PagerStyle
BackColor
="#FFCC66"
ForeColor
="#333333"
HorizontalAlign
="Center"
/>
<
HeaderStyle
BackColor
="#990000"
Font-Bold
="True"
ForeColor
="White"
/>
<
AlternatingRowStyle
BackColor
="White"
/>
</
asp:GridView
>
</
div
>
</
form
>
</
body
>
</
html
>
后台代码:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Data.SqlClient;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
Button1_Click1(
object
sender, EventArgs e)
{
string
connstr
=
ConfigurationManager.AppSettings[
"
ConnectionString
"
].ToString();
SqlConnection con
=
new
SqlConnection(connstr);
if
(con.State.Equals(ConnectionState.Closed))
{
con.Open();
}
string
procName
=
"
dbo.GetTitleTop
"
;
SqlCommand cmd
=
new
SqlCommand(procName, con);
cmd.CommandType
=
CommandType.StoredProcedure;
cmd.Parameters.Add(
"
@kindid
"
, SqlDbType.Int);
cmd.Parameters.Add(
"
@IntTop
"
, SqlDbType.Int);
cmd.Parameters[
0
].Value
=
Convert.ToInt32(
this
.txtKindId.Text.Trim());
cmd.Parameters[
1
].Value
=
Convert.ToInt32(
this
.txtIntTop.Text.Trim());
SqlDataReader sdr
=
cmd.ExecuteReader(CommandBehavior.CloseConnection);
this
.GridView1.DataSource
=
sdr;
this
.GridView1.DataBind();
}
}
查看全文
相关阅读:
k-匿名算法
门控循环单元(GRU)与 LSTM 的区别
计算机视觉之相机成像原理:世界坐标系、相机坐标系、图像坐标系、像素坐标系之间的转换
CMU-Multimodal SDK Version 1.1 (mmsdk)使用方法总结
机器学习 – 练习题:一段1米长的绳子 随机切两刀 分成三段 求能够组合成一个三角形的概率
pickle导入变量AttributeError的解决方案
typing类型注解库
灰度共生矩阵(Gray-level Co-occurrence Matrix,GLCM),矩阵的特征量
几何不变矩--Hu矩
对 GAN 的 value function 的理解
原文地址:https://www.cnblogs.com/wbcms/p/1037564.html
最新文章
DOI(数字对象标识)官方手册学习笔记
SD-WAN技术详解
OHEM
Batch Normalization
机会网络概述
社会技术系统(Sociotechnical System)
WGS84、GCJ02、BD09 坐标系之间的转换算法
二分图的最大匹配、完美匹配和匈牙利算法
mAP的代码实现及分析
优化器算法Optimizer详解(BGD、SGD、MBGD、Momentum、NAG、Adagrad、Adadelta、RMSprop、Adam)
热门文章
Python装饰器
Python 生成器和迭代器,yield语句
功率谱和频谱的区别、联系
论文翻译:Data mining with big data
LATEX 数学公式基本语法
重温拉格朗日乘子法和KKT条件
StarGAN学习笔记
专题:机器学习中的相似性度量
Big Data Hubris:"大数据傲慢"问题
Space Syntax(空间句法)
Copyright © 2011-2022 走看看