Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a recordset with C Sharp 2

Status
Not open for further replies.

plsh

Programmer
Mar 5, 2003
118
ZA
Good day,

I am hoping someone can help. I am very new to C Sharp and am trying to learn it. I have quite a lot of experience with straight ASP and have been doing sites for a few years now. Below is a piece of code I have from straight ASP using VB Script. I would like to know what the equivalent in C Sharp, can anyone help?

Dim Con, RS
Con = CreateObject("ADODB.Connection")
Con.Open ("Provider=SQLOLEDB;Data Source=SERVER;Initial Catalog=DB;UID=username")

RS = CreateObject("ADODB.Recordset")
sSQL = "Select * from TABLE"
RS.Open (sSQL, Con, 3)


Thanks in advance
 
You can use ASP Style also here but you have to add ADODB reference to the project.
you can found in
Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll
or look for adodb.dll and add to your reference.

Code:
ADODB.ConnectionClass con=new ADODB.ConnectionClass();
ADODB.RecordsetClass rs=new ADODB.RecordsetClass();
con.Open("Driver={SQL Server};Server=localhost;Database=northwind;Uid=sa;Pwd=;Trusted_Connection=yes;","","",0);
//more code

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thanks George,

Just one more thing, how would I open the recordset, much the way I had it?
 
Well you can use .NET way of doing that also
Code:
using System.Data;
using System.Data.OleDb;

...

OleDbConnection con=new OleDbConnection(connStr);
con.Open();
OleDbDataReader rs=new OleDbDataReader();
OleDbCommand cmd=new OleDbCommand();
cmd.Connection=con;
cmd.CommandText="select * from table1";
cmd.CommandType=CommandType.Text;
rs=cmd.ExecuteReader(CommandBehavior.CloseConnection);
while(rs.Read())
{
	string data1=rs["name"].ToString();
}

also for using old style way
Code:
ADODB.ConnectionClass con=new ADODB.ConnectionClass();
ADODB.RecordsetClass rs=new ADODB.RecordsetClass();
con.Open("Driver={SQL Server};Server=localhost;Database=northwind;Uid=sa;Pwd=test;Trusted_Connection=yes;Network=DBMSSOCN","","",0);
rs.Open("select * from table1",con,ADODB.CursorTypeEnum.adOpenStatic,ADODB.LockTypeEnum.adLockOptimistic,0);
int reccount=rs.RecordCount;
while(!rs.EOF)
{
	string data=rs.Fields["name"].Value;
	rs.MoveNext();
}

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thanks George,

You have been a great help, appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top