想做一个数据库的条件查询,如下图:通过对某一项打勾,从而获得该项的名称。自定义了一个函数获取唯一值的函数获得该field下的所有值,恰巧要用到checkedboxlist中被选中项的名称。 可是不知道怎么获取其名称,希望大家给看看。下面是获取唯一值得函数,也请大家批评指正。
public static string QueryFieldValue(String accessPath, string tableName, string fieldName,string key)
        {
            
            String accdbConnectionSring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + accessPath;
            OleDbConnection conn = new OleDbConnection(accdbConnectionSring);
            String command = "select "+fieldName+" from "+tableName+"where 县名='"+key+"'";
            try
            {
                conn = new OleDbConnection(accdbConnectionSring);
                conn.Open();
                OleDbCommand queryCmd = new OleDbCommand(command, conn);
                queryCmd.Parameters.AddWithValue(tableName, key);
                string fieldValue = queryCmd.ExecuteScalar().ToString();
                conn.Close();
                return fieldValue;
            }
            catch
            {
                conn.Close();
                return null;
            }
        }数据库checkedboxlist

解决方案 »

  1.   

    checkedListBox里面的各项只有一个值,没有名称            checkedListBox1.Items[0].ToString();//这个是获取第一列的内容
                checkedListBox1.SelectedItem.ToString();//这个是获取当前选中列的内容
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    int check = checkedListBox1.CheckedItems.Count;//这个是获取当前勾选列的列数
                    checkedListBox1.CheckedItems[0].ToString();//这个是获取当前勾选列中第一列的内容
                }