OleDbDataReader doubt

fahjblffela

New Member
I have a procedure with 2 sql statements (for example) in it.How will retrieve the values of both the sql statements using either OleDbDataReader or any other methods.I found this (hope it helps)...<BR>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpcontheadonetdatareader.asp<BR><BR><BR>[Visual Basic]<BR>Dim myCMD As SqlCommand = New SqlCommand("SELECT CategoryID, CategoryName FROM Categories;" & _<BR> "SELECT EmployeeID, LastName FROM Employees", nwindConn)<BR>nwindConn.Open()<BR><BR>Dim myReader As SqlDataReader = myCMD.ExecuteReader()<BR><BR>Dim fNextResult As Boolean = True<BR>Do Until Not fNextResult<BR> Console.WriteLine(vbTab & myReader.GetName(0) & vbTab & myReader.GetName(1))<BR><BR> Do While myReader.Read()<BR> Console.WriteLine(vbTab & myReader.GetInt32(0) & vbTab & myReader.GetString(1))<BR> Loop<BR><BR> fNextResult = myReader.NextResult()<BR>Loop<BR><BR>myReader.Close()<BR>nwindConn.Close()<BR>[C#]<BR>SqlCommand myCMD = new SqlCommand("SELECT CategoryID, CategoryName FROM Categories;" +<BR> "SELECT EmployeeID, LastName FROM Employees", nwindConn);<BR>nwindConn.Open();<BR><BR>SqlDataReader myReader = myCMD.ExecuteReader();<BR><BR>do<BR>{<BR> Console.WriteLine(" {0} {1}", myReader.GetName(0), myReader.GetName(1));<BR><BR> while (myReader.Read())<BR> Console.WriteLine(" {0} {1}", myReader.GetInt32(0), myReader.GetString(1));<BR><BR>} while (myReader.NextResult());<BR><BR>myReader.Close();<BR>nwindConn.Close();<BR>I tried also the same i.e., a procedure with 2 select statements.It didnt work out.I could not find the examples for the same.Any way for one sql statement, u can use my code.If you find any , kindly email me the link or the code to [email protected].<BR><BR><BR> Dim strConnect As String = "Provider=SQLOLEDB;data source=localhost;initial catalog=databaseName;UID=sa;pwd=;"<BR> Dim objConnect As New OleDbConnection(strConnect)<BR> Dim objCommand As New OleDbCommand("MyProc", objConnect)<BR> Dim objReader As OleDbDataReader<BR><BR> objCommand.CommandType = CommandType.StoredProcedure<BR> Dim objParam As OleDbParameter<BR> objParam = objCommand.Parameters.Add("FName", OleDbType.Char, 20)<BR> objParam.Direction = ParameterDirection.Input<BR> objParam.Value = http://aspmessageboard.com/archive/index.php/"Beulah"<BR> Try<BR> objCommand.Connection.Open()<BR> objReader = objCommand.ExecuteReader<BR> Catch myException As OleDbException<BR> Response.Write("Error retrieving data.")<BR> End Try<BR> While objReader.Read()<BR> Dim Info1 As String = objReader("UInfo").ToString()<BR> Dim Year1 As Integer = Year(objReader("UDate"))<BR> Dim Month1 As Integer = Month(objReader("Udate"))<BR> Dim Day1 As Integer = Day(objReader("Udate"))<BR> End While<BR><BR> objReader.Close()<BR> objCommand.Connection.Close()<BR><BR><BR>Anymore clarifications, u can email me...
 
Back
Top