在postgresql中从2个不同的表填充2个checkedlistbox

时间:2015-08-07 03:34:01

标签: c# postgresql

从上面的标题中,我在c#中创建了一个windows表单,其中2个我的checkedlistbox应该填充数据库中2个表的值。但是,当我尝试运行代码时,我总是得到这个异常:“无法绑定到新的值成员”。

下面是我的代码。如果您能找到任何错误/建议,请随时发表评论。这将是一个很大的帮助。谢谢!

DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            DataTable dt2 = new DataTable();

            string connstring = ("Server=localhost;Port=5432;User Id=postgres;Password=021393;Database=postgres;");
            NpgsqlConnection conn = new NpgsqlConnection(connstring);
            NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM data_condition", conn);
            cmd.CommandType = CommandType.Text;
            conn.Open();
            NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd);
            dt.TableName = "data_condition";
            da.Fill(dt);
            checkedListBox1.DataSource = dt;
            checkedListBox1.DisplayMember = "conname";
            checkedListBox1.ValueMember = "conid";
            string[] condition = dt.Rows[0]["conname"].ToString().Split(',');

            NpgsqlCommand cmd2 = new NpgsqlCommand("SELECT * FROM data_allergy", conn);
            cmd2.CommandType = CommandType.Text;        
            NpgsqlDataAdapter da2 = new NpgsqlDataAdapter(cmd2);
            dt2.TableName = "data_allergy";
            da2.Fill(dt2);
            checkedListBox2.DataSource = dt2;
            checkedListBox2.DisplayMember = "allergyname";
            checkedListBox2.ValueMember = "allerygid";
            string[] allergy = dt2.Rows[0]["allergyname"].ToString().Split(','); 

0 个答案:

没有答案
相关问题