如何根据表选择从Mysql获取所有列名 [英] How can get all column name from Mysql as per table selection
本文介绍了如何根据表选择从Mysql获取所有列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的c#代码我想要表格列名
尝试
{
使用(MySqlConnection con = new MySqlConnection(txtOtherConStr.Text.Trim()))
{
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(txtOtherConStr.Text.Trim());
string db = builder.Database;
使用(MySqlCommand cmd = new MySqlCommand( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = + db + AND TABLE_NAME = @ TABLE_NAME,con))
{
cmd.Parameters.Add( @ TABLE_NAME,MySqlDbType.VarChar).Value = lbOtherTable.SelectedValue;
new MySqlDataAdapter(cmd).Fill(dt);
}
}
}
catch {}
这是我的sql查询,但我没有得到帮助我是一些知道的解决方案
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = + db + AND TABLE_NAME = @ TABLE_NAME
解决方案
参考:获取表格列mysql中的名称? [ ^ ]
Below is my c# code i want table column name
try
{
using (MySqlConnection con = new MySqlConnection(txtOtherConStr.Text.Trim()))
{
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(txtOtherConStr.Text.Trim());
string db = builder.Database;
using (MySqlCommand cmd=new MySqlCommand("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "+ db +" AND TABLE_NAME =@TABLE_NAME",con))
{
cmd.Parameters.Add("@TABLE_NAME", MySqlDbType.VarChar).Value = lbOtherTable.SelectedValue;
new MySqlDataAdapter(cmd).Fill(dt);
}
}
}
catch { }
This is my sql query but i am not get pls help me is some know solution
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "+ db +" AND TABLE_NAME =@TABLE_NAME
解决方案
refer: Get table column names in mysql?[^]
这篇关于如何根据表选择从Mysql获取所有列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文