在创建文件时无法将从数据库中提取的值用作变量 [英] Unable to use values extracted from database as variables in file creation

查看:71
本文介绍了在创建文件时无法将从数据库中提取的值用作变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!-/*样式定义*/p.MsoNormal,li.MsoNormal,div.MsoNormal {mso-style-parent:";边距:0cm;底边距:.0001pt; mso分页:寡妇孤儿;字体大小:12.0pt; mso-bidi-font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-fareast-language:EN-US;} @page Section1 {size:612.0pt 792.0pt;保证金:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;}->我编写了一个网页,该网页连接到数据库,然后使用该数据库显示来自管理报告系统的3个值.

我正在使用以下代码访问数据库:

< asp:SqlDataSource ID =" SqlToVersion" runat =服务器"
ConnectionString ="<%$ ConnectionStrings:WebImportOnServer%>"
SelectCommand ="从[atblVersion]中选择[VerNo],[PeriodName],[PeriodNo]"
onselecting ="SqlToVersion_Selecting"</asp:SqlDataSource>
< asp:DetailsView ID ="DetView" runat =服务器" DataSourceID ="SqlToVersion";
Height ="50px" onpageindexchanging ="DetView_PageIndexChanging2";
Width ="273px" AutoGenerateRows =" False">
< Fields>
< asp:BoundField DataField =" VerNo" HeaderText =电子表格版本号"; ReadOnly ="True" />
< asp:BoundField DataField =" PeriodName" HeaderText =报告期间" ReadOnly ="True"
SortExpression ="PeriodName"; />
< asp:BoundField DataField =" PeriodNo" HeaderText =期间号"; ReadOnly ="True"
SortExpression ="PeriodNo" />
</Fields>
</asp:DetailsView>

这是完美的方法,但是我需要采用3个数据字段中显示的值(VerNo,

我的变量是以这种方式定义的:
Dim vcPeriodNo As Integer = ????

,但是这是如何用有效的代码替换问号的方法,该代码从我坚持使用的绑定字段中获取值.任何人都可以提供任何建议,我知道它应该很简单,但是我遇到了一个完整的问题.

<!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; mso-bidi-font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-fareast-language:EN-US;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> I have written a web page which connects to a database and then display 3 values from a management reporting system using the database.

I am accessing a database using the following code:

<asp:SqlDataSource ID="SqlToVersion" runat="server"
ConnectionString="<%$ ConnectionStrings:WebImportOnServer %>"
SelectCommand="SELECT [VerNo], [PeriodName], [PeriodNo] FROM [atblVersion]"
onselecting="SqlToVersion_Selecting"></asp:SqlDataSource>
<asp:DetailsView ID="DetView" runat="server" DataSourceID="SqlToVersion"
Height="50px" onpageindexchanging="DetView_PageIndexChanging2"
Width="273px" AutoGenerateRows="False">
<Fields>
<asp:BoundField DataField="VerNo" HeaderText="Spreadsheet Version Number" ReadOnly="True" />
<asp:BoundField DataField="PeriodName" HeaderText="Reporting Period" ReadOnly="True"
SortExpression="PeriodName" />
<asp:BoundField DataField="PeriodNo" HeaderText="Period Number" ReadOnly="True"
SortExpression="PeriodNo" />
</Fields>
</asp:DetailsView>

This works perfectly, but I need to take the values displayed in the 3 datafields (VerNo , PeriodName PeriodNo ) and use them as variables in a file that is being generated from the web page.

My variables are defined in this manner:
Dim vcPeriodNo As Integer = ????

but it is how to replace the question marks with valid code that  takes the values from the bound fields that I am stuck with. Can anyone offer any advice, I know it should be simple but I have hit a complete block.

推荐答案

我不知道您使用的是哪种代码样式(在页或带有代码隐藏的内容)

有很多解决方案,最容易入门的是SQL DataReader.
(此页面上的示例很容易理解)

http://msdn.microsoft .com/en-us/library/system.data.sqlclient.sqldatareader(VS.71).aspx

在您使用的列名中更改此示例中的0和1 "VerNo","PeriodName"和"PeriodNo"

使用起来比使用过的更安全

myReader.GetString(1)



myReader.GetString("PeriondName")

希望对您有所帮助,

Cor
I am not known aware which code style you use (on the page or with codebehind)

There are many solutions, the most easiest one to start with is proably the SQL DataReader.
(And the example on this page is very easy to understand)

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader(VS.71).aspx

Change the 0 and the 1 in this sample in the by you used columnames "VerNo", "PeriodName" and "PeriodNo"

That is more secure to use then the used

myReader.GetString(1)

This would become in your situation

myReader.GetString("PeriondName")

I hope this helps,

Cor


这篇关于在创建文件时无法将从数据库中提取的值用作变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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