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();
}
}
查看全文
相关阅读:
判断无向图G是否连通
图的深度优先搜索与广度优先搜索
整数变换问题
按层次遍历二叉树
交叉链表
二元查找树转换成一个排序的双向链表
简单计算器的实现
二叉树宽度的计算
BMP文件的读取与显示
约瑟夫环问题
原文地址:https://www.cnblogs.com/wbcms/p/1037564.html
最新文章
路由分发的本质
Forms组件
form表单和ajax发送文件以及ajax发送json字符串
分页
MVC与MTV
Django中间键
auth
Python求阴影部分面积
微信跳一跳辅助自动跳Python
win10 64位下VirtualBox安装CentOS6.9
热门文章
Django--ORM高级查询
Django--ORM多对多表操作
django--ORM基础
django路由系统
JQuery的Ajax
form表单
web框架--django基础简介
http协议
JavaScript与页面交互
javas运算符
Copyright © 2011-2022 走看看