如何使用asp.net从sql服务器中检索用户数据 [英] how to retrieve user data from the sql server using asp.net

查看:62
本文介绍了如何使用asp.net从sql服务器中检索用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此有任何身体帮助.

谢谢,

any body help about this.

thanks,

推荐答案

尝试此链接

点击 [
try this link

Click[^]


SqlDataReader provides a means of reading a forward-only stream of data records from a SQL Server data source. For more interactive operations such as scrolling, filtering, navigating, and remoting, use the DataSet.
The example creates a SqlConnection to the Northwind database. The SqlCommand selecting items from the employee table is then executed using the SqlCommand ExecuteReader method. The results of this command are passed to the SqlDataReader.




SqlDataReader myDataReader = null;

SqlConnection mySqlConnection =新的SqlConnection("server =(local)\ SQLExpress; Integrated Security = SSPI; database = northwind");
SqlCommand mySqlCommand =新的SqlCommand("SELECT EmployeeID,LastName,FirstName,Title,ReportsTo FROM Employees",mySqlConnection);
...
mySqlConnection.Open();
myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection);




SqlDataReader myDataReader = null;

SqlConnection mySqlConnection = new SqlConnection("server=(local)\SQLExpress;Integrated Security=SSPI;database=northwind");
SqlCommand mySqlCommand = new SqlCommand("SELECT EmployeeID, LastName, FirstName, Title, ReportsTo FROM Employees", mySqlConnection);
...
mySqlConnection.Open();
myDataReader = mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection);

The example reads through the data using the SqlDataReader Read method and writing the data elements out to the console.

    while (myDataReader.Read())
    {
      Console.Write(myDataReader.GetInt32(0) + "\t");
      Console.Write(myDataReader.GetString(2) + " " + myDataReader.GetString(1) + "\t");
      Console.Write(myDataReader.GetString(3) + "\t");
      if (myDataReader.IsDBNull(4))
        Console.Write("N/A\n");
      else
        Console.Write(myDataReader.GetInt32(4) + "\n");
    }





Finally, the example closes the SqlDataReader, then the SqlConnection.

    // Always call Close when done reading.
    myDataReader.Close();
    // Close the connection when done with it.
    mySqlConnection.Close();



或者,您也可以单击

[
这里]



Or You can do it by alternate way click

[Here]


这篇关于如何使用asp.net从sql服务器中检索用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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