Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...

C#
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........................
Posted
Updated 9-Mar-12 8:11am
v2

1 solution

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:
C#
using System.Data.SqlClient;
At the top of your file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900