我有一个c#windows 连接mysql数据库的问题

xyzsorry 2008-05-28 08:39:56
c#windows中使用coboBox控件,下拉后显示mysql数据库中表的内容。可以用coboBox绑定数据库,可是显示出的有重复项(因为数据库中的表有重复项)

想用代码实现这一功能,不能有重复。

谢谢,不胜感激!
...全文
148 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyzsorry 2008-05-28
  • 打赏
  • 举报
回复
没事的,我再想想其他的办法。谢谢你了!
amandag 2008-05-28
  • 打赏
  • 举报
回复
很明显根本不是sql语句的问题,而是你的连接就没打开

偶对MySql研究不多,只能say sorry了
xyzsorry 2008-05-28
  • 打赏
  • 举报
回复
myConnection.Open();有错误。

MySQLDriverCS Exception: MySQLDriverCS Error: can't connect.Access denied for user 'ODBC'@'localhost' (using password: NO)
amandag 2008-05-28
  • 打赏
  • 举报
回复
这样试试
string find = "select distinct casing1 from 1";
string connStr = "server=localhost;uid=root;pwd=1;database= design";
MySQLConnection myConnection = new MySQLConnection(connStr);
MySQLDataAdapter myda = new MySQLDataAdapter(find, myConnection);
DataSet ds = new DataSet();
myConnection.Open();
myda.Fill(ds);
myConnection.Close();
comboBox1.DataSource = ds.Tables[0].DefaultView;
comboBox1.DisplayMember = "casing1";
amandag 2008-05-28
  • 打赏
  • 举报
回复
就是有错误。
==
什么错误
xyzsorry 2008-05-28
  • 打赏
  • 举报
回复
不会。我知道要用distinct,可是代码不知道怎么写。

mysql第一次用。
private void Form1_Load(object sender, EventArgs e){
string find = "select distinct casing1 from 1";
string connStr = "server=localhost;uid=root;pwd=1;database= design";
MySQLConnection myConnection = new MySQLConnection(connStr);
MySQLDataAdapter myda = new MySQLDataAdapter(find, myConnection);
DataSet ds = new DataSet();
myda.Fill(ds, "ds");

comboBox1.DisplayMember = "casing1";


comboBox1.DataSource = ds.Tables["ds"].DefaultView;
}
就是有错误。
xyzsorry 2008-05-28
  • 打赏
  • 举报
回复
能说的详细点吗?
把distinct写到具体的那一段?
private void Form1_Load(object sender, EventArgs e){}?
还是
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){}?
amandag 2008-05-28
  • 打赏
  • 举报
回复
不是已经回过一贴了么?楼主还不会使用distinct?
ccssddnnhelp 2008-05-28
  • 打赏
  • 举报
回复

把combox的数据源改为

select distinct fldname from tblName.
==== ====

.
贴子分数<20:对自已的问题不予重视。
贴子大量未结:对别人的回答不予尊重。
.

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧