Foros del Web » Programación para mayores de 30 ;) » .NET »

Ayuda con este error!!!!! Please

Estas en el tema de Ayuda con este error!!!!! Please en el foro de .NET en Foros del Web. Este error me genera... Compiler Error Message: BC30002: Type 'SqlDataReader' is not defined. Source Error: Line 20: MyConnection.Open() Line 21: Line 22: Dim dr As ...
  #1 (permalink)  
Antiguo 09/01/2005, 19:26
Avatar de univercity  
Fecha de Ingreso: noviembre-2002
Mensajes: 681
Antigüedad: 21 años, 5 meses
Puntos: 0
Ayuda con este error!!!!! Please

Este error me genera...

Compiler Error Message: BC30002: Type 'SqlDataReader' is not defined.
Source Error:
Line 20: MyConnection.Open()
Line 21:
Line 22: Dim dr As SqlDataReader = MyCommand.ExecuteReader()
Line 23:
Line 24: MyDataGrid.DataSource = dr

-----------------------------------------------------------------
Y este es el codigo que estoy utilizando...


Sub Page_Load(Sender As Object, E As EventArgs)
Dim strConexion As String
Dim DS As DataSet
Dim MyConnection As OleDbConnection
Dim MyCommand As OleDbDataAdapter
strConexion = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("../bdwine/clientes.mdb")
MyConnection = New OleDbConnection(strConexion)
MyCommand = New OleDbDataAdapter("select top 1 * from tabla1 ", MyConnection)

MyConnection.Open()

Dim dr As SqlDataReader = MyCommand.ExecuteReader()

MyDataGrid.DataSource = dr
MyDataGrid.DataBind()

MyConnection.Close()

End Sub


hace rato que estoy parado ahi, por favor alguien que me tienda una mano...
__________________
"Lo importante es nunca dejar de hacerse preguntas"
Albert Einstein
  #2 (permalink)  
Antiguo 10/01/2005, 01:47
Avatar de ORendon  
Fecha de Ingreso: diciembre-2004
Ubicación: Med-Colombia
Mensajes: 46
Antigüedad: 19 años, 4 meses
Puntos: 0
Tengo varias dudas con respecto a tu codigo
En primera instancia porque has definido el DataReader derivado de la clase sqlClient y no de la clase Oledb ¿?
Y segundo, no me gusta para nada tu command, que no deberia ser un OledCommand ¿?
Revisa esto para que se ejecute efectivamente el executeReader(), y luego me cuentas.

Ay te ves
  #3 (permalink)  
Antiguo 10/01/2005, 04:28
Avatar de univercity  
Fecha de Ingreso: noviembre-2002
Mensajes: 681
Antigüedad: 21 años, 5 meses
Puntos: 0
ahora me dice esto...

Compiler Error Message: BC30456: 'ExecuteReader' is not a member of 'System.Data.OleDb.OleDbDataAdapter'.

Source Error:



Line 20: MyConnection.Open()
Line 21:
Line 22: Dim dr As OleDbDataReader = MyOledbCommand.ExecuteReader()
Line 23:
Line 24: MyDataGrid.DataSource = dr
__________________
"Lo importante es nunca dejar de hacerse preguntas"
Albert Einstein
  #4 (permalink)  
Antiguo 10/01/2005, 06:38
 
Fecha de Ingreso: octubre-2004
Mensajes: 15
Antigüedad: 19 años, 7 meses
Puntos: 0
No estoy seguro pero creo que es porque tu OleDbDataReader no lo as definido como un objeto. Prueba esto:

dim dr as OleDbDataReader = new OleDbDataReader()
dr = MyCommand.ExecuteReader()

o directamente

MyDataGrid.DataSource = MyCommand.ExecuteReader()
  #5 (permalink)  
Antiguo 10/01/2005, 07:06
Avatar de xknown  
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.248
Antigüedad: 19 años, 4 meses
Puntos: 7
Hola, por el error supongo que no estás utilizando codebehind, prueba agregando en la parte superior de tu página:

Código HTML:
<%@ Import Namespace="System.Data" %>
 <%@ Import Namespace="System.Data.SqlClient" %> 
Acerca de lo que dijo Jose_minglein:
Código:
dim dr as OleDbDataReader = new OleDbDataReader()
No se puede hacer eso ya que los DataReader's (SQL u OleDb) son interfaces y estas no pueden ser creadas directamente a partir de New.

Saludos
__________________
Alex Concha
Buayacorp - Programación y Diseño
  #6 (permalink)  
Antiguo 10/01/2005, 14:19
Avatar de univercity  
Fecha de Ingreso: noviembre-2002
Mensajes: 681
Antigüedad: 21 años, 5 meses
Puntos: 0
si los codebehind, estan puestos...

<%@ Import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>


ahora el codigo compelto quedo ahroa así...

<%@ Import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<html>
<head>


</head>

<script language="VB" runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)
Dim strConexion As String
Dim DS As DataSet
Dim MyConnection As OleDbConnection
Dim MyOledbCommand As OleDbDataAdapter
strConexion = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("../bdwine/clientes.mdb")
MyConnection = New OleDbConnection(strConexion)
MyOledbCommand = New OleDbDataAdapter("select top 1 * from tabla1 ", MyConnection)

MyConnection.Open()
dim dr as OleDbDataReader = new OleDbDataReader()
dr = MyCommand.ExecuteReader()


'Dim dr As OleDbDataReader = MyOledbCommand.ExecuteReader()

MyDataGrid.DataSource = dr
MyDataGrid.DataBind()

MyConnection.Close()

End Sub

</script>


y me genera este error...


Compiler Error Message: BC30390: 'System.Data.OleDb.OleDbDataReader.Private Sub New(connection As System.Data.OleDb.OleDbConnection, command As System.Data.OleDb.OleDbCommand, depth As Integer, chapter As System.IntPtr)' is not accessible in this context because it is 'Private'.

Source Error:



Line 19:
Line 20: MyConnection.Open()
Line 21: dim dr as OleDbDataReader = new OleDbDataReader()
Line 22: dr = MyCommand.ExecuteReader()
Line 23:

error en linea 21
__________________
"Lo importante es nunca dejar de hacerse preguntas"
Albert Einstein
  #7 (permalink)  
Antiguo 10/01/2005, 14:44
Avatar de xknown  
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.248
Antigüedad: 19 años, 4 meses
Puntos: 7
El codebehind significa que separas el código (vb o cs) de la presentación(pagina.aspx), me interpretaste mal. El ejemplo que muestras no es codebehind, es al estilo de las páginas asp.

Volviendo al tema anterior, si tomaste atención al mensaje que envié diciendo que: "los DataReader's (SQL u OleDb) son interfaces y estas no pueden ser creadas directamente a partir de New"

Lo siguiente está mal
Cita:
Iniciado por univercity
dim dr as OleDbDataReader = new OleDbDataReader()
debería ser:
Código:
dim dr as OleDbDataReader 


Intenta con los siguientes códigos:

Código:
 <%@ Page Language="VB" %>
 <%@ Import Namespace="System.Data" %>
 <%@ import Namespace="System.Data.OleDb" %>
 <html>
 <head>
 <script language="VB" runat="server">
 Sub Page_Load(Sender As Object, E As EventArgs)
 		Dim strConexion As String
 	Dim DS As DataSet
 	Dim MyOledbDA As OleDbDataAdapter
 	strConexion = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("../bdwine/clientes.mdb")
 	MyOledbDA = New OleDbDataAdapter("select top 1 * from tabla1 ", strConexion)
 
 	MyOledbDA.Fill(DS,"tabla1")
 
 	MyDataGrid.DataSource = DS
 	MyDataGrid.DataBind()
 End Sub
 
 </script>
 </head>
 ...
o
Código:
<%@ Page Language="VB" %>
 <%@ Import Namespace="System.Data" %>
 <%@ import Namespace="System.Data.OleDb" %>
 <html>
 <head>
 <script language="VB" runat="server">
 Sub Page_Load(Sender As Object, E As EventArgs)
 		Dim strConexion As String
 	Dim MyConnection As OleDbConnection
 	Dim MyOledbCommand As OleDbCommand
 	strConexion = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("../bdwine/clientes.mdb")
 	MyConnection = New OleDbConnection(strConexion)
 	MyOledbCommand = New OleDbCommand("select top 1 * from tabla1 ", MyConnection)
 
 	MyConnection.Open()
 
 	dim dr as OleDbDataReader = MyOledbCommand.ExecuteReader(CommandBehavior.CloseConnection)
 
 	MyDataGrid.DataSource = dr
 	MyDataGrid.DataBind()
 End Sub
 
 </script>
 </head>
 ...
__________________
Alex Concha
Buayacorp - Programación y Diseño
  #8 (permalink)  
Antiguo 13/01/2005, 05:51
 
Fecha de Ingreso: enero-2005
Mensajes: 23
Antigüedad: 19 años, 3 meses
Puntos: 0
Mensaje Ayuda con este error!!!!! Please

intentalo con esto

Dim strConexion As String
Dim MyConexion As OleDbConnection
Dim MyComando As OleDbDataAdapter
Dim MyDS As New DataSet
strConexion = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("../bdwine/clientes.mdb")
MyConexion = New OleDbConnection(strConexion)
MyComando = New OleDbDataAdapter("Select * From tabla1", strConexion)
MyComando.Fill(MyDS, "tabla1")
MyDataGrid.DataSource = MyjDS
MyDataGrid.DataBind()
MyConexion.Close()
  #9 (permalink)  
Antiguo 13/01/2005, 05:55
 
Fecha de Ingreso: enero-2005
Mensajes: 23
Antigüedad: 19 años, 3 meses
Puntos: 0
Mensaje Ayuda con este error!!!!! Please

Elimina la j en la linea

MyDataGrid.DataSource = MyjDS

Perdona el error.
  #10 (permalink)  
Antiguo 13/01/2005, 06:31
 
Fecha de Ingreso: abril-2002
Mensajes: 30
Antigüedad: 22 años
Puntos: 1
Te recomiendo no usar DataSet en web a menos que sea por algun motivo de peso, son muy lentos y pesados. Puedes usar IDataReader y asi te da igual el proveedorde BBDD que tengas, te funcionara de todas formas.

Pon IDataReader en la ayuda (SDK, MSDN o lo que tengas) que viene un ejemplito, es muy facil.

Lo basico seria...

...
IDataReader dr = XXXCommand.ExecuteReader();
...
__________________
enadan
  #11 (permalink)  
Antiguo 13/01/2005, 06:41
Avatar de univercity  
Fecha de Ingreso: noviembre-2002
Mensajes: 681
Antigüedad: 21 años, 5 meses
Puntos: 0
Ok. voy a probar con los aportes que me han hecho les comento luego, gracias a todos...
__________________
"Lo importante es nunca dejar de hacerse preguntas"
Albert Einstein
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:42.