从SQL Server数据库中查找和获取数据 [英] Find and GET data from SQL Server Database

查看:110
本文介绍了从SQL Server数据库中查找和获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我一直在使用System.Data.SqlClient

我试图弄清楚如何查找特定数据并从中获取其他信息.就像我想找到一个具有特定名称的数据,并且想要获得它的ID号和/或行号.我还不知道该怎么做.需要帮助!我研究了查询字符串和SQLCommand.我还不知道该怎么做.就像我希望它能够向我返回一些东西.

In C# I have been using the System.Data.SqlClient

I am trying to figure out how to find a certain data and get something else from it. Like I want to find a piece of Data which has a certain name, and I want to get it''s Id number and/or row number. I haven''t found out how to do it. Need helps! I''ve looked into query strings and SQLCommand. I haven''t found out how to do this. Like I want it to be able return something to me.

推荐答案

这是一个不错的起点: ASP.NET Web表单 [ ^ ]

[更新]
像RaviRanjankr一样建议这样做可以很好地工作,但是它不允许您利用平台的数据绑定功能.阅读这些教程将使您以更少的工作完成更多的工作.

最好的问候
Espen Harlinn
This is a great place to start: ASP.NET Data Access Tutorials[^]

You might take a look at the other material too:
ASP.NET Web Forms[^]

[Update]
Doing it like RaviRanjankr suggests works fine, but it will not allow you to take advantage of the databinding features of the platform. Going through the tutorials will allow you to get more done with less work.

Best regards
Espen Harlinn


您可以使用ADO.NET DataReader从数据库中检索只读的,仅转发的数据流.查询执行时将返回结果,并将结果存储在客户端的网络缓冲区中,直到您使用SqlDataReader的Read方法请求它们为止.

You can use the ADO.NET DataReader to retrieve a read-only, forward-only stream of data from a database. Results are returned as the query executes, and are stored in the network buffer on the client until you request them using the Read method of the SqlDataReader.

SqlConnection con = new SqlConnection();
con.ConnectionString = "Write your Connection String values";
con.Open();
SqlCommand cmd = new SqlCommand("Your query using Where Clause",con);
            SqlDataReader dr = cmd.ExecuteReader();
 if(dr.Read())
{
// if dr is able to read value or dr have more than 0 rows
var value = dr[index] // assign 
}



有关更多详细信息,请查看此 Link-MSDN- [使用DataReader] [ ^ ]



for more Details take a look at this Link-MSDN-[Retrieving Data Using the DataReader][^]


您可以使用已连接或已断开连接的体系结构从数据库检索数据.
您需要修改您的选择查询.
此链接对u
可能有用 -------------------------------------------------- ----------------------
http://amul-aspnetsampleprojects.blogspot.com/2011/07/deleteupdate-data- offlineed.html [ ^ ]

-------------------------------------------------- -----------------------

http://amul-aspnetsampleprojects.blogspot.com [
You can retrieve data from database using connected or disconnected architecture.
u need to modify ur select query.
this link can be useful to u
------------------------------------------------------------------------
http://amul-aspnetsampleprojects.blogspot.com/2011/07/deleteupdate-data-disconnected.html[^]

-------------------------------------------------------------------------

http://amul-aspnetsampleprojects.blogspot.com[^]


这篇关于从SQL Server数据库中查找和获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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