如何将数据库与ASP.NET应用程序连接 [英] How to Connect DB with ASP.NET Application

查看:92
本文介绍了如何将数据库与ASP.NET应用程序连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
建立与数据库和ASP.NET应用程序的连接的最佳方法是什么.
请给我建议选项,并简要介绍一下...该怎么做.
谢谢,


Itz.Irshad

Hi Guys,
What is best methodology for establishing a connection with database and ASP.NET Application.
Kindly, suggest me options and brief also...how to do that.
Thanks,


Itz.Irshad

推荐答案

使用ADO.NET和Google

ADO.NET概述 [
Use ADO.NET and Google

ADO.NET Overview[^]


查看此链接,您可能会有所了解
ADO.NET 101:SQL连接 [ http://stackoverflow.com/questions/5642474/在asp-net-to-sql-server上设置设置连接字符串 [
see this link you may get some idea
ADO.NET 101: SQL Connection[^]

http://stackoverflow.com/questions/5642474/setting-up-connection-string-in-asp-net-to-sql-server[^]



  1. 获取适合您的RDBMS类型的连接字符串:可在此处找到帮助! [

  1. Fetch yourself a connection string appropriate for your kind of RDBMS: Help can be found here![^]
  2. Then try this here:
String queryString = "SELECT OrderID, CustomerID FROM dbo.Orders;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
    SqlCommand command = new SqlCommand(queryString, connection);
    connection.Open();
    SqlDataReader reader = command.ExecuteReader();
    try
    {
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0, {1", reader[0], reader[1]));
        }
    }
    finally
    {
        // Always call Close when done reading.
        reader.Close();
    }
}





问候,

曼弗雷德(Manfred)



Regards,

Manfred


这篇关于如何将数据库与ASP.NET应用程序连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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