S
Sharon
Hi all
I want to return OleDbDataReader from a static function,
So I will have DB interface for my Entire project,
Is it possible?
How do I close the connection ??????
Thank you
Sharon
/////////////////////////////////////////////////////////////
//Example of use :
/////////////////////////////////////////////////////////////
OleDbDataReader reader = myDbObj.Select("SELECT CustomerID, ContactName,
FROM Customers")
While (reader.Read()){
System.diagnostics.Trace.WriteLine(reader("CustomerID").ToString()
+ " : " + reader("ContactName").ToString() + "<br>")
}
/////////////////////////////////////////////////////////////
//select function :
/////////////////////////////////////////////////////////////
Public static OleDbDataReader Select (string selectString)
{
'Use a string variable to hold the ConnectionString property.
String connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\\Program
Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB"
OleDbConnection cn = New OleDbConnection(connectString)
'Open the connection.
cn.Open()
'Use a variable to hold the SQL statement.
String As String =
OleDbCommand cmd = New OleDbCommand(selectString, cn)
Return cmd.ExecuteReader()
'Close the reader and the related connection.
// reader.Close()
//??????????????????????????????????????????????????
cn.Close()
}
I want to return OleDbDataReader from a static function,
So I will have DB interface for my Entire project,
Is it possible?
How do I close the connection ??????
Thank you
Sharon
/////////////////////////////////////////////////////////////
//Example of use :
/////////////////////////////////////////////////////////////
OleDbDataReader reader = myDbObj.Select("SELECT CustomerID, ContactName,
FROM Customers")
While (reader.Read()){
System.diagnostics.Trace.WriteLine(reader("CustomerID").ToString()
+ " : " + reader("ContactName").ToString() + "<br>")
}
/////////////////////////////////////////////////////////////
//select function :
/////////////////////////////////////////////////////////////
Public static OleDbDataReader Select (string selectString)
{
'Use a string variable to hold the ConnectionString property.
String connectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\\Program
Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB"
OleDbConnection cn = New OleDbConnection(connectString)
'Open the connection.
cn.Open()
'Use a variable to hold the SQL statement.
String As String =
OleDbCommand cmd = New OleDbCommand(selectString, cn)
Return cmd.ExecuteReader()
'Close the reader and the related connection.
// reader.Close()
//??????????????????????????????????????????????????
cn.Close()
}