Hello FelipX,
Your getting an incorrect format exception whilst trying to parse your
DataTable column to Int32 could be as a result of the existence of non numeric
characters in the value that you are trying to parse.
You are trying to return the name of your column and then parse it to a 32 bit
integer value. I am not really sure why you would want to do that as I believe
you column name is most likely not an integer but alphanumeric.
If on the other hand what you want to parse to int32 is the contents of the
cells of the row returned from your DataTable, then you are using the wrong
syntax. You can use this to get the contents of the cells of the DataRow of
your DataTable.
if (myDT.Rows.Count > 0)
{
auxidcodigo = int.Parse(myDT.Rows[0][0].ToString().Trim());
auxtipocodigo = myDT.Rows[0][1].ToString().Trim();
auxcodigo = myDT.Rows[0][1].ToString().Trim();
DGV_Codigos_Producto.Rows.Add(auxidcodigo, auxtipocodigo,
auxidcodigo);
}
I hope this helps you and others.
Regards,
Chike
________________________________
From: FelipeX <[email protected]>
To: "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
Services,.NET Remoting" <[email protected]>
Sent: Tuesday, November 22, 2011 9:09 PM
Subject: [DotNetDevelopment] Problem loading a datagridview from a DataTable
I am trying to do the following:
myDT =
C_Articulo.Cargar_Codigo_Articulo(int.Parse(Txt_Id_Producto.Text));
int auxidcodigo;
string auxtipocodigo, auxcodigo;
if (myDT.Rows.Count > 0)
{
auxidcodigo = int.Parse(myDT.Columns[0].ToString());
auxtipocodigo = myDT.Columns[1].ToString();
auxcodigo = myDT.Columns[2].ToString();
DGV_Codigos_Producto.Rows.Add(auxidcodigo, auxtipocodigo,
auxidcodigo);
}
The method Cargar_Codigo_Articulo has the following code:
//------------------------------------------------------------------
public DataTable Cargar_Codigo_Articulo(int L_Id_Articulo)
{// Devuelve todos los codigos de un determinado articulo
MySql.Data.MySqlClient.MySqlConnection conn;
String ConStr;
Global_Proc CGlobal = new Global_Proc();
ConStr = CGlobal.BuscarConnString(CGlobal.archivoConfiguracion);
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = ConStr;
conn.Open(); //Abro la conexion
// Crea el command de la consulta
MySql.Data.MySqlClient.MySqlCommand CommSql = new
MySql.Data.MySqlClient.MySqlCommand();
// Asigno la conexion al command
CommSql.Connection = conn;
// Ingreso la consulta a ejecutar
CommSql.CommandText = "Select
codigo_articulo.Id_Tipo_Codigo,parametro.Descripcion,codigo_articulo.codigo
"
+"from codigo_articulo inner join
parametro "
+"on parametro.Id_Parametro =
codigo_articulo.Id_Tipo_Codigo where "
+"Id_Articulo = @PId_Articulo "
+ "order by
parametro.Descripcion asc";
CommSql.Parameters.AddWithValue("@PId_Articulo",
L_Id_Articulo);
MySql.Data.MySqlClient.MySqlDataAdapter myDA =
new
MySql.Data.MySqlClient.MySqlDataAdapter(CommSql);
DataTable myDT = new DataTable();
myDA.Fill(myDT);
conn.Close(); //Cierro la conexion
return myDT;
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
return null;
// Aqui deberia enviar algun tipo de mensaje sobre la
excepcion
}
}// fin del Metodo Cargar_Grupo_Parametro
//------------------------------------------------------------------
but the problem is that in the line
auxidcodigo = int.Parse(myDT.Columns[0].ToString());
Throw a incorrect fomat exception.
How can I fix this?
Greetings and thks
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net