xpmaster Posted November 25, 2010 Report Share Posted November 25, 2010 HOLA AMIGOS , MI PROBLEMA ES EL SIGUIENTE QUIERO CARGAR LOS DATOS DE UN DATASET A TEXTBOX EL PROBLEMA ES Q NO SE QUE AGO MAL QUE NO ME FUNCA UNA PARTE DEL CODIGO LA PARTE DEL FINAL LO MANDO COMPLETO PARA Q SE ENTIENDA SqlConnection MC2 = new SqlConnection(); MC2.ConnectionString = "Server=(local);" + "DataBase=Mantenedor ;Integrated Security=true"; /* probar la conexion abriendola */ MC2.Open(); /* creamos un objeto sqlcommmand */ SqlCommand MiComando = new SqlCommand(); /* le indicamos al sqlcommand la conexion a utilizar*/ MiComando.Connection = MC2; /* configuro la sentencia SQL*/ MiComando.CommandText = "SELECT Nombre_Producto,Valor_Producto FROM Productos WHERE Productos.Id_Producto LIKE '" + TxtIdBucar + "'"; /*creamos un objeto 100% conectado [sqlDataAdapter]*/ /*Le pasamos como parametro de creación el sqlcommand llamado MiComnado */ SqlDataAdapter MiDataAdapter = new SqlDataAdapter(MiComando); /*Crear un objeto desconectado DataSet */ DataSet MiDataSet = new DataSet(); /* Ahora hay que llenar el dataset por medio del sqlDataAdapter */ MiDataAdapter.Fill(MiDataSet); textBox6.Text =MiDataSet .Tables(0).Rows(0)(0); <---------ERASE AKI MI PROBLEMA ME IRA ERROR EN EL .Tables QUE SERA ESTOY ASIENDO MAL ?? Link to comment Share on other sites More sharing options...
Ra Posted November 26, 2010 Report Share Posted November 26, 2010 Se eliminó el tema repetido... Está prohibido el doble post... Link to comment Share on other sites More sharing options...
The Duke of Quakem Posted November 26, 2010 Report Share Posted November 26, 2010 (edited) textBox6.Text =MiDataSet .Tables(0).Rows(0)(0); <---------ERASE AKI MI PROBLEMA ME IRA ERROR EN EL .Tables Si es C#, debes usar paréntesis cuadrados para moverte por las colecciones y/o array de datos. textBox6.Text =MiDataSet .Tables[0].Rows[0][0]; Para declaracion y llamado de clases, objetos, métodos, etc. se usan los paréntesis redondos. ah! y como recomendación, usa el doble slash (//) para las líneas de comentarios y comentarios al final de la línea de código. El /* y */ se usa generalmente para comentar cosas entre medio del código o cuando comentas mas de una línea seguida. Edited November 26, 2010 by The Duke of Quakem Link to comment Share on other sites More sharing options...
MrAnderson Posted November 29, 2010 Report Share Posted November 29, 2010 Seguramente te está arrojando un error de conversión, y es porque estás tratando de asignarle esto: MiDataSet .Tables(0).Rows(0)(0) que creo que es un Object, a la propiedad Text de un de un Textbox, la cual es de tipo String. Suerte. Link to comment Share on other sites More sharing options...
Ra Posted November 30, 2010 Report Share Posted November 30, 2010 Viejo... MiDataSet .Tables(0).Rows Devuelve una colección de objetos DataRow, por lo tanto, es como un array. Por su parte un DataRow es otro array que contiene las columnas... Entonces, en C# tendría que ser así: MiDataSet .Tables[0].Rows[0][0] En Visual Basic es con ( )... Recuerda que en C los array se manejan con [ ] y los ( ) denotan los argumentos para la llamada a una función... En Visual Basic, los ( ) se usan para ambas cosas... Salu2. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now