ASP.NET中不使用LINQ訪問 mssql server 2005資料庫解決辦法

來源:互聯網
上載者:User

asp教程.net中不使用linq訪問 mssql server 2005資料庫教程解決辦法

asp.net教程應用程式的資料訪問是通過ado.net完成的,ado.net可以使web應用程式從各種資料來源中快速存取資料。

在asp.net中不使用linq訪問資料庫,而是通過寫sql文直接存取microsoft sql server 2005

1.添加引用system.configuration,並在程式中使用命名空間using system.configuration。

2."configurationmanager.connectionstrings["connectionstring"].connectionstring"中方括弧中引號內的字串和我的工程中web.config設定檔中<connectionstrings></connectionstrings>標記中的屬性"name="mywebconnectionstrings""的字串不一致。正確的應為屬性name中的字串。

3.沒有開啟資料庫連接。因為我的程式中缺少l了"sqlcon.open();”這句代碼。

using system.data.sqlclient;
using system.configuration;

protected void setorders(sting morders)
       {
string sqlconnstr = configurationmanager.connectionstrings["mywebconnectionstrings"].connectionstring;
                sqlconnection sqlcon = new sqlconnection(sqlconnstr);
                sqlcommand commd = new sqlcommand();
                commd.connection = sqlcon;
                sqlcon.open();
                commd.commandtext = "update  orderlist set status = 1 where (orderid in (" + mpayingnum + ")"+")";
                sqldatareader sqldatareader = commd.executereader();
                commd = null;
                sqlcon.close();
                sqlcon = null;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.