日期:2014-05-18  浏览次数:20820 次

c#组合框显示
各位大侠:小弟想把数据库中表的一列显示到组合框中,如下式代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 组合框显示
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

  private void Form1_Load(object sender, EventArgs e)
  {
  string connString = @"server=PC20110019JN;uid=sa,pwd=123;database=fjf;";
  string sql = @"select 客户编码,客户名称 from 客户资料";
  SqlConnection conn = new SqlConnection(connString);
  SqlCommand cmd = new SqlCommand(sql, conn);
  conn.Open();
  SqlDataReader read = cmd.ExecuteReader();
  while (read.Read())
  {
  国家列表.Items.Add(read["客户编码"].ToString);//此处为用ADD方法直接往控件里添加内容,
  }
  read.Close();
  conn.Close();
  }
   
  }
}
可调试时总是有两个错误:错误1、与“System.Windows.Forms.ComboBox.ObjectCollection.Add(object)”最匹配的重载方法具有一些无效参数
错误2、参数“1”: 无法从“方法组”转换为“object”

错误1在“国家列表.Items.Add(read["客户编码"].ToString);//此处为用ADD方法直接往控件里添加内容,”处,
错误2在“read["客户编码"].ToString”处。
不知道是什么原因,指点指点啊!谢谢了!

------解决方案--------------------
ToString也应该加个括号吧ToString()
------解决方案--------------------
read["客户编码"].ToString()
少了括号
------解决方案--------------------
你的ToString少了括号,正确应该是ToString()才行
------解决方案--------------------
咕~~(╯﹏╰)b
ToString是方法怎么能不加括号。。。