How to change DataType into coresponding MySqlType ??

How to change DataType into coresponding MySqlType ??

Postby AceEmbler » Wed 04 Oct 2006 11:16

I have got DataTable.Column[].DataType how to change it into MySqlType.

I need it for parameters in MysqlDataTable.UpdateCommand.
AceEmbler
 
Posts: 26
Joined: Fri 04 Aug 2006 09:45

Postby Alexey » Wed 04 Oct 2006 12:36

Please describe in detail what exactly you need or what is the problem.
Take a look at the code below:
Code: Select all
mySqlDataTable1.SelectCommand.Parameters.Add("paramName", MySqlType.Int);
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby AceEmbler » Thu 05 Oct 2006 08:31

Alexey wrote:Please describe in detail what exactly you need or what is the problem.
Take a look at the code below:
Code: Select all
mySqlDataTable1.SelectCommand.Parameters.Add("paramName", MySqlType.Int);


As I have mentioned before I have filled DataTable with data from database, but I dont know of what type specified column is. But I can get Column data Type like that DataTable.Column[].DataType , but it is not MysqlType which is needed in Parameters but Type. How can I know what MysqlType corespod to which Type.
AceEmbler
 
Posts: 26
Joined: Fri 04 Aug 2006 09:45

Postby Alexey » Thu 05 Oct 2006 09:00

If you need to know colunms' data types of any table, create a MySqlDataAdapter, configure it with select command like
Code: Select all
select * from
Press Preview button and then press Schema Tables button.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby AceEmbler » Thu 05 Oct 2006 09:12

Alexey wrote:If you need to know colunms' data types of any table, create a MySqlDataAdapter, configure it with select command like
Code: Select all
select * from

Press Preview button and then press Schema Tables button.

I need to know it at run time.
AceEmbler
 
Posts: 26
Joined: Fri 04 Aug 2006 09:45

Postby Alexey » Thu 05 Oct 2006 09:26

Then use the following code:
Code: Select all
      MySqlConnection conn = new MySqlConnection("");
      MySqlCommand cmd = new MySqlCommand("select * from
", conn);
      conn.Open();
      MySqlDataReader reader = cmd.ExecuteReader();
      DataTable dt = reader.GetSchemaTable();
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby AceEmbler » Thu 05 Oct 2006 10:02

Alexey wrote:Then use the following code:
Code: Select all
      MySqlConnection conn = new MySqlConnection("");
      MySqlCommand cmd = new MySqlCommand("select * from
", conn);
      conn.Open();
      MySqlDataReader reader = cmd.ExecuteReader();
      DataTable dt = reader.GetSchemaTable();


And how am I suposed to use this column data type obtained by your sniplet in:
UpdateCommand.Parameters.Add(); //??
AceEmbler
 
Posts: 26
Joined: Fri 04 Aug 2006 09:45

Postby Alexey » Thu 05 Oct 2006 10:30

OK, use GetSchema() method of MySqlConnection component:
Code: Select all
      MySqlConnection conn = new MySqlConnection(""); 
      MySqlCommand cmd = new MySqlCommand("select * from
where =:", conn);
      DataTable dt = conn.GetSchema("Columns", new string[] { "", "
", "%" });
      cmd.Parameters.Add("", dt.Rows[].ItemArray[dt.Columns["DataType"].Ordinal].ToString());
      cmd.Parameters[""].Value = ;
      MySqlDataReader reader = cmd.ExecuteReader();
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL

Copyright © 1998 - 2016 Devart. All rights reserved.