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();
}
}
查看全文
相关阅读:
查前端资料的一些网站
10.18号笔记
10.17号笔记
10.16号笔记
10.13号笔记
10.12号笔记
10.11号笔记
10.10号笔记
10.9号笔记
理想VS现实
原文地址:https://www.cnblogs.com/wbcms/p/1037564.html
最新文章
跨浏览器的打印程序的设计
记录一次升级kernel
Linux命令-重启命令reboot与shutdown的区别
记录cobbler报错
Windows下安装apache
keepalived的配置文件
搭建Keepalived+LNMP架构web动态博客 实现高可用与负载均衡
使用python3搭建Linux-mariadb主从架构
Linux-安装python3环境
Linux-day-1
热门文章
数据分析:.Net程序员该如何选择?
.Net实现拉勾网爬虫
pgsql 变量赋值方法
PG 存储函数调用变量的3种方法。
c# 访问postgressql,使用pghelper访问pgsql
SQL 列转行 分组去重并合并多条记录
SQL 去重 显示第一条数据 显示一条数据
SQL 查询某时间段的数据 datadiff 计算时间差
SQL 列转行,即多行合并成一条
nodejs在windows下的安装配置(使用NVM的方式)
Copyright © 2011-2022 走看看