新问题 [英] Newby question

查看:83
本文介绍了新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我一开始需要帮助。我一直在为一些

时间编写经典ASP,但是从SQL数据库中获取数据并显示单个值

包括我。


到目前为止,我有以下代码:


Dim myConnection As New SqlConnection(" UID = dbuser; PWD = thepass; Data

来源= SQLServer;初始目录=数据库;")

Dim myCommand As New SqlDataAdapter(从产品中选择名称代码=

0117",myConnection)

Dim ds作为新数据集()

myCommand.Fill(ds," Name")


来获取记录在数据库之外。我现在要做的就是将名称放在

中,记录到变量中并在HTML文本中使用它。我很感激

任何帮助。


谢谢

赫尔曼

Hi

I need help at the very beginning. I have been writing classic ASP for some
time, but getting data out of a SQL database and displaying a single value
eludes me.

So far I have the following code:

Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
Source=SQLServer;Initial Catalog=database;")
Dim myCommand As New SqlDataAdapter("select Name from Products where code =
0117", myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds, "Name")

to get a record out of the database. All I want to do now put the Name in
that record into a variable and use it in the HTML text. I would appreciate
any help.

Thank you
Hermann

推荐答案

首先,Fill方法是SqlDataAdapter类的一个方法,所以使用

填充,你必须先创建一个数据适配器,但你不要对于你正在做的事情,我们需要一个

数据集。使用

SqlCommand类的ExecuteScalar()方法返回单个值。搜索框架

文档从数据库中获取单个值。


为了在HTML中使用该服务器端变量,请执行此操作就像你在经典ASP中使用
一样:


< p>产品代码0117的产品名称是:<%= myVariable%>。< ; / p>

Dale


" Hermann W Ehlers" <他***** @ AThawkspoint.com>在消息中写道

新闻:我们************* @ TK2MSFTNGP11.phx.gbl ...
First off, the Fill method is a method of the SqlDataAdapter class so to use
Fill, you''d have to create a data adapter first, but you don''t need a
dataset for what you''re doing. Use the ExecuteScalar() method of the
SqlCommand class to return a single value. Search the framework
documentation for "Obtaining a Single Value from a Database".

In order to use that server side variable in your HTML, do it just as you
would in classic ASP:

<p>Product name for product code 0117 is: <%= myVariable %>.</p>
Dale

"Hermann W Ehlers" <he*****@AThawkspoint.com> wrote in message
news:us*************@TK2MSFTNGP11.phx.gbl...

<我一开始就需要帮助。我一直在以
编写经典ASP,但是从SQL数据库中获取数据并显示单个值
包括我。

到目前为止,我有以下代码:

将myConnection调暗为新的SqlConnection(UID = dbuser; PWD = thepass;数据
Source = SQLServer;初始目录=数据库;)
将myCommand调暗为新的SqlDataAdapter (从代码
= 0117的产品中选择姓名,myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds," Name")

从数据库中获取记录。我现在要做的就是将记录中的Name放入变量并在HTML文本中使用它。我会
感谢任何帮助。

谢谢
Hermann
Hi

I need help at the very beginning. I have been writing classic ASP for some time, but getting data out of a SQL database and displaying a single value
eludes me.

So far I have the following code:

Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
Source=SQLServer;Initial Catalog=database;")
Dim myCommand As New SqlDataAdapter("select Name from Products where code = 0117", myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds, "Name")

to get a record out of the database. All I want to do now put the Name in
that record into a variable and use it in the HTML text. I would appreciate any help.

Thank you
Hermann



Hello Hermann ,


对于你在这里想要完成的事情,数据集可能完全过分。


试试这个:


(c#代码,但VB应该非常相似)

SqlConnection myConnection = new SqlConnection(" UID = dbuser; PWD = thepass; Data Source = server; Initial Catalog =数据库;");

SqlCommand cmd = new SqlCommand(从代码= 0117",myConnection的产品中选择名称);


string s = (字符串)cmd.ExecuteScalar();


ExecuteScalar将从数据库中接收一个值。你可以把它变成合适的类型。


HTH,


-

马特Berther
http://www.mattberther.com
Hello Hermann,

An dataset is probably complete overkill for what you''re trying to accomplish here.

Try this:

(c# code, but VB should be pretty similar)
SqlConnection myConnection = new SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial Catalog=database;");
SqlCommand cmd = new SqlCommand("select name from products where code = 0117", myConnection);

string s = (string)cmd.ExecuteScalar();

ExecuteScalar will receive one value from a database. It is up to you to cast it to the appropriate type.

HTH,

--
Matt Berther
http://www.mattberther.com


Hello DalePres,


Dale,在他的代码示例中,他正在创建一个SqlDataAdapter。变量名称错了。 ;)
Hello DalePres,

Dale, in his code example, he was creating a SqlDataAdapter. The variable name was just wrong. ;)
首先,Fill方法是SqlDataAdapter类的一个方法,所以
使用Fill,你必须先创建一个数据适配器,但是你不需要一个数据集来处理你正在做的事情。使用SqlCommand类的ExecuteScalar()方法返回单个值。在
框架文档中搜索从
数据库中获取单个值。

为了在HTML中使用该服务器端变量,请将其作为
< p>产品代码0117的产品名称为:<%= myVariable%>。< / p>

Dale

Hermann W Ehlers <他***** @ AThawkspoint.com>在消息中写道
新闻:我们************* @ TK2MSFTNGP11.phx.gbl ...
First off, the Fill method is a method of the SqlDataAdapter class so
to use Fill, you''d have to create a data adapter first, but you don''t
need a dataset for what you''re doing. Use the ExecuteScalar() method
of the SqlCommand class to return a single value. Search the
framework documentation for "Obtaining a Single Value from a
Database".

In order to use that server side variable in your HTML, do it just as
you would in classic ASP:

<p>Product name for product code 0117 is: <%= myVariable %>.</p>

Dale

"Hermann W Ehlers" <he*****@AThawkspoint.com> wrote in message
news:us*************@TK2MSFTNGP11.phx.gbl...

<我一开始就需要帮助。我一直在编写经典的ASP
Hi

I need help at the very beginning. I have been writing classic ASP
for


时间,但是从SQL数据库中获取数据并显示单个
价值包括我。

到目前为止,我有以下代码:

Dim myConnection As New SqlConnection(" UID = dbuser; PWD = thepass; Data
Source = SQLServer;初始目录=数据库;")
Dim myCommand As New SqlDataAdapter(从产品中选择名称
代码
time, but getting data out of a SQL database and displaying a single
value eludes me.

So far I have the following code:

Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
Source=SQLServer;Initial Catalog=database;")
Dim myCommand As New SqlDataAdapter("select Name from Products where
code


=


=

0117",myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds," Name")
获取记录数据库。我现在要做的就是将该记录中的
Name放入变量中并在HTML文本中使用它。我会
0117", myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds, "Name")
to get a record out of the database. All I want to do now put the
Name in that record into a variable and use it in the HTML text. I
would


欣赏


appreciate

任何帮助。

谢谢
赫尔曼
any help.

Thank you
Hermann



-

-

Matt Berther
http://www.mattberther.com


这篇关于新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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