我只是想抓住一个领域! [英] I just want to grab one field!!

查看:52
本文介绍了我只是想抓住一个领域!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是ASP.NET,VB等的新手...我来自一个
冷融合背景,我只需要4行来查询MSSQL数据库

并显示一个字段名称。


请问,如何使用DSN(mydsnname)然后

选择thisfieldname来自thistablename。


然后如何在我的html页面中显示该值?


....稍后我会问如何获取上传的文件名称,并通过另一种形式更新相同的

字段.....


大图:我有一个现有的aspx页面我需要添加一个链接。

超链接应该指向服务器上的一个文件,我可以通过

上传表单来更改....


正如我所说,我是CFer ......但必须在.Net环境中这样做。


感谢您的帮助!!!


-

通过 http://发布消息www.dotnetmonster.com

解决方案

你应该看看:
http://www.dotnetjunkies.com/quickst...ataaccess.aspx


一旦你建立了连接和命令,就可以通过命令的ExecuteScalar

方法来检索单个字段


public共享函数GetValue()as string

dim connection as new SqlConnection(" ConnectionString")

dim命令as new Sql命令(从表中选择字段,连接)

尝试

connection.Open()

返回cstr(command.ExecuteScalar)

终于

connection.Dispose()

command.Dispose()

结束尝试

结束功能


这是假设字段是一个字符串/ char / varchar / text你会cint()它如果

它是一个int / long / xxx,cbool如果它有点......等等


就使用DSN而言,你不能将它与SqlConnection一起使用..来自文档:

SQL Server的.NET Framework数据提供程序使用自己的协议

与SQL Server通信。因此,它不支持在连接到SQL Server时使用

ODBC数据源名称(DSN),因为它确实没有添加ODBC层。

不添加ODBC层。


所以你可以使用OleDbConnection和OleDbCommand。


Karl

-

MY ASP.Net教程
http://www.openmymind.net /index.aspx - 新增和改进(是的,弹出窗口是

烦人)
http://www.openmymind.net/faq.aspx - 非官方新闻组常见问题解答(更多内容

来了!)

" Jonathan Schwarz来自DotNetMonster.com" < FO *** @ DotNetMonster.com>写在

消息新闻:55 ****************************** @ DotNetMonste r.com。 ..

大家好,我是ASP.NET,VB等的新手......我来自一个冷融合背景,我只需要4行查询一个MSSQL数据库
并显示一个字段名称。

请问,如何使用DSN(mydsnname)连接到我的SQL数据库,然后选择thisfieldname ;来自thistablename。

然后如何在我的html页面中显示该值?

...稍后我会问如何获取上传的文件名并更新同一个
字段通过另一种形式.....

大图:我有一个现有的aspx页面,我需要添加一个链接。
超链接应该指向服务器上的一个文件,我可以通过
上传表单进行更改但尚未创建....

正如我所说,我是CFer ...但必须在.Net环境中这样做。

感谢您的帮助!

-
通过 http://www.dotnetmonster.com



表名:mei_cc_file

字段:id(int),filnam(varchar)

记录:1


我只需要展示如何显示filnam的内容。在aspx

网页上。我只计划使用这个数据库和表格,而不是别的。

有人能告诉我如何使用完全局部变量来完成这项工作

和参数(没有其他的)文件)?


正如我所说的,我是VB的新手,和.Net ...所以请简单


:)


-

通过发布消息http://www.dotnetmonster.com


<%@ Imports Namespace =" System.Data.SqlClient

< html>

< head>< / head>

< body>

< asp:literal id ="文件名" RUNAT = QUOT;服务器" />

< / body>


Sub Page_Load

dim连接为新的SqlConnection(CONNECTION_STRING)

dim命令为新的SqlCommand (" SELECT Filname from mei_cc_file where id =

@ id",connection)

command.Parameters.Add(" @ Id",SqlDbType.Int).Value = 1

尝试

connection.open()

lit.text = cstr(command.ExecuteScalar())

终于

connection.dispose()

command.dispose()

结束尝试

结束Sub < br $> b $ b< / script>

查看 http://www.w3schools.com/aspnet/aspnet_dbconnection.asp ...代码

可能不像我输入的那样工作它离我的头顶,但应该是

关闭...


Karl


-

我的ASP.Net教程
http://www.openmymind.net/index.aspx - 新增和改进(是的,弹出窗口是

烦人的)
http://www.openmymind.net/faq.aspx - 非官方新闻组常见问题解答(更多内容

来了!)

" Jonathan Schwarz来自DotNetMonster.com" < FO *** @ DotNetMonster.com>写在

消息新闻:dd ****************************** @ DotNetMonste r.com。 ..

表名:mei_cc_file
字段:id(int),filnam(varchar)
记录:1

我只需要显示如何显示filnam的内容在aspx
网页上。我只计划使用这个数据库和表格,而不是别的。
有人可以告诉我如何使用完全局部变量
和参数(没有其他文件)吗?

正如我所说的,我是VB的新手,和.Net ...所以请简单

:)

-
留言通过 http://www.dotnetmonster.com



Hi folks, I am a complete newbie to ASP.NET, VB, etc... I am coming from a
Cold Fusion background where it only takes me 4 lines to query a MSSQL db
and display a field name.

Please, how do I connect to my SQL db using the DSN ("mydsnname") and then
select "thisfieldname" from "thistablename".

Then how do i display the value in my html page?

....later I will ask how to grab an uplaoded files name and update the same
field via another form.....

Big Picture: I ahve an existing aspx page that I need to add a link to. The
hyperlink should point to a file on the server that I can change via an
upload form yet to be created....

As I said, I am a CFer... but have to do this in a .Net environment.

Thanks for any help!!!

--
Message posted via http://www.dotnetmonster.com

解决方案

You should take a look at:
http://www.dotnetjunkies.com/quickst...ataaccess.aspx

Once you have your connection and command set up, you can the ExecuteScalar
method of the command to retrieve a single field

public shared function GetValue() as string
dim connection as new SqlConnection("ConnectionString")
dim command as new SqlCommand("select field from table", connection)
try
connection.Open()
return cstr(command.ExecuteScalar)
finally
connection.Dispose()
command.Dispose()
end try
end function

this is assuming "field" is a string/char/varchar/text you''ll cint() it if
it''s a int/long/xxx, cbool if it''s a bit...and so on

As far as using a DSN, you can''t use it with SqlConnection..from the docs:
The .NET Framework Data Provider for SQL Server uses its own protocol to
communicate with SQL Server. Therefore, it does not support the use of an
ODBC data source name (DSN) when connecting to SQL Server because it does
not add an ODBC layer.

so you could make use of an OleDbConnection and OleDbCommand instead.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/index.aspx - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonathan Schwarz via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:55******************************@DotNetMonste r.com...

Hi folks, I am a complete newbie to ASP.NET, VB, etc... I am coming from a
Cold Fusion background where it only takes me 4 lines to query a MSSQL db
and display a field name.

Please, how do I connect to my SQL db using the DSN ("mydsnname") and then
select "thisfieldname" from "thistablename".

Then how do i display the value in my html page?

...later I will ask how to grab an uplaoded files name and update the same
field via another form.....

Big Picture: I ahve an existing aspx page that I need to add a link to. The hyperlink should point to a file on the server that I can change via an
upload form yet to be created....

As I said, I am a CFer... but have to do this in a .Net environment.

Thanks for any help!!!

--
Message posted via http://www.dotnetmonster.com



Table name: mei_cc_file
Fields: id(int), filnam(varchar)
Records: 1

I just need to be shown how to display the contents of "filnam" on an aspx
web page. I only plan to use this db and table for this and nothing else.
Can someone show me how this can be done with completely local variables
and parameters (nothing from another file)?

As I said, I am new to VB, and .Net... so please be simple

:)

--
Message posted via http://www.dotnetmonster.com


<%@ Imports Namespace="System.Data.SqlClient
<html>
<head></head>
<body>
<asp:literal id="fileName" runat="server" />
</body>

<script runat="Server" language="vb">
Sub Page_Load
dim connection as new SqlConnection("CONNECTION_STRING")
dim command as new SqlCommand("SELECT Filname from mei_cc_file where id =
@id", connection)
command.Parameters.Add("@Id", SqlDbType.Int).Value = 1
try
connection.open()
lit.text = cstr(command.ExecuteScalar())
finally
connection.dispose()
command.dispose()
end try
End Sub
</script>

Check out http://www.w3schools.com/aspnet/aspnet_dbconnection.asp ...code
might not work as is as I''ve typed it off the top of my head, but should be
close...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/index.aspx - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonathan Schwarz via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:dd******************************@DotNetMonste r.com...

Table name: mei_cc_file
Fields: id(int), filnam(varchar)
Records: 1

I just need to be shown how to display the contents of "filnam" on an aspx
web page. I only plan to use this db and table for this and nothing else.
Can someone show me how this can be done with completely local variables
and parameters (nothing from another file)?

As I said, I am new to VB, and .Net... so please be simple

:)

--
Message posted via http://www.dotnetmonster.com



这篇关于我只是想抓住一个领域!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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