Jump to content

Ayuda en C#


Recommended Posts

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

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 by The Duke of Quakem
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...