Home > Database > Mysql Tutorial > ASP.NET中不使用LINQ访问 mssql server 2005数据库解决办法

ASP.NET中不使用LINQ访问 mssql server 2005数据库解决办法

WBOY
Release: 2016-06-07 17:47:57
Original
1167 people have browsed it

.net中不使用linq访问 mssql server 2005解决办法

应用程序的数据访问是通过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配置文件中标记中的属性"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;
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template