如何处理Asp.net中的mysql tinyint字段,c#gridview? [英] how to handle mysql tinyint field in Asp.net,c# gridview?
问题描述
亲爱的所有人,
我正在尝试连接到mysql数据库。我能够从表中获取记录但字段类型为tinyint(1)转换到前端的方框。 Mysql数据库是一个拥有10000多个表的共享数据库,无权修改它。所以需要一个通用的解决方案来显示。我尝试了很多,但没有什么对我有用。下面是代码和数据库条目。
代码:
Dear All,
I am trying to connect to mysql database.I am able to fetch the records from a table but the field type tinyint(1) convert to square box in front end. Mysql database is a shared database with 10000+ tables And have no authority to modify it. so need a generic solution to display.I tried a lot but nothing works for me. Below is the code and database entry.
Code:
MySqlConnection conn = new MySqlConnection(mysqlstring);
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM avg_product";
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
GridView2.DataSource = ds.Tables[0].DefaultView;
GridView2.DataBind();
数据库:
字段的值为0或1.
Visual Studio中的数据集Visualizer显示为TRUE / FALSE。在浏览器的前端,Gridview显示一个方框(类型的复选框)。
请帮帮我。在此先感谢。
database:
field has values as 0 or 1.
Dataset Visualizer in visual studio showing as TRUE/FALSE.On front end in browser,Gridview shows a square box(kind of checkbox).
Please help me. Thanks in advance.
推荐答案
只需将值转换为
select cast(tinyintcol as int),来自tbl
这应该有用
just cast the value as
select cast(tinyintcol as int) , from tbl
this should work
这篇关于如何处理Asp.net中的mysql tinyint字段,c#gridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!