asp.net和sql server 2000代码. [英] asp.net and sql server 2000 code.

查看:79
本文介绍了asp.net和sql server 2000代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生
我对使用ms-access的asp.net很熟悉.但是现在我要使用sql server,请问您可以帮助我将以下代码更改为sql .....
我将SQL Server 2000与vs 2010一起使用.
如果在任何行中都不需要任何更改,请也告诉我...

连接字符串 = "  来自表名称"  abc  );
   DataGrid1.Datasource = ds;
 DataGrid1.Datamember =" abc  ;  





谢谢你........................

解决方案

更改连接字符串.尝试设置使用服务器资源管理器"窗格在VS中建立连接:

 1)打开服务器资源管理器.
2)右键单击数据连接",然后选择添加连接"
3)在随后的对话框中,选择您的数据源和数据库,指定安全信息,然后按测试连接"按钮.
4)连接正常后,按确定"
5)在服务器资源管理器"窗格中突出显示您的数据库,然后查看属性"窗格.将显示一个连接字符串的工作示例,您可以将其复制并粘贴到您的应用程序或配置文件中.



将OdbcConnection替换为SqlConection

用SqlDataAdapter替换OdbcDataAdapter

您应该会发现它几乎可以正常工作.该代码片段至少应该.

您可能需要添加:

 使用 System.Data.SqlClient; 

在文件顶部.


Sir
I m familiar to asp.net with ms-access. but now i want to use sql server can u please help me to change the following code to sql.....
I use sql server 2000 with vs 2010..
if any change not required in any line then please also tell me...

connection string = "provider =microsoft.jet.odbc.4.0; 

Dataset ds;
      OdbcConnection cn;
     ds = new dataset();
     String st = "select * from table name";
    Odbc Data Adapter adp = new Odbc Data Adapter(st,cn);
   int r = adp.fill(ds,"abc");
   DataGrid1.Datasource =ds;
 DataGrid1.Datamember ="abc";





thank u........................

解决方案

Change the connection string.Try setting up a connection in VS with the Server Explorer pane:

1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.



Replace OdbcConnection with SqlConection

Replace OdbcDataAdapter with SqlDataAdapter

You should find it works, pretty much. That code fragment should, at least.

You will probably have to add:

using System.Data.SqlClient;

At the top of your file.


这篇关于asp.net和sql server 2000代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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