arraylist组合框中的错误 [英] Error in arraylist combobox

查看:104
本文介绍了arraylist组合框中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我想通过arraylist从数据库中选择项目,但项目没有显示在组合框中。我的程序中有什么错误请告诉我。





Dear All,

I want to select the item from the database through arraylist but the item not showing in the combobox. what is the error in my program please tell me.


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            cmboItemType();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void cmboItemType()    //for combobox 
        {
            string connstr = @"Server=.\SQLEXPRESS ;Initial Catalog=RPSJDB;Integrated Security=True; Max Pool Size=100";
            SqlConnection conn = new SqlConnection(connstr);
            SqlCommand cmd = new SqlCommand("SELECT cmbItemType FROM ItemTable", conn);
            conn.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            ArrayList ItemStore = new ArrayList();
            while (sdr.Read())
            {
                ItemStore.Add(sdr.ToString());
            }
            sdr.Close();
            conn.Close();
        }
}
}
        }

推荐答案

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            cmboItemType();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void cmboItemType()    //for combobox 
        {
            string connstr = @"Server=.\SQLEXPRESS ;Initial Catalog=RPSJDB;Integrated Security=True; Max Pool Size=100";
            SqlConnection conn = new SqlConnection(connstr);
            SqlCommand cmd = new SqlCommand("SELECT cmbItemType FROM ItemTable", conn);
            conn.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            ArrayList ItemStore = new ArrayList();
int i=0;
            while (sdr.Read())
            {

                ItemStore.Add(sdr[i].ToString());
i++;
            }
            sdr.Close();
            conn.Close();
        }
    }
}
}



检查这个............. 。

http:// stackoverflow .com / questions / 256832 / c-sharp-a-combo-box-with-a datatable [ ^ ]


我不确定但是先检查在sql server中你在sqlCommand中给出的查询天气返回值



如果没有检查列名和表名





如果这一切都正确,那么检查连接字符串中的目录名称是指数据库名称
i am not sure but first check ur query in sql server that u have given in sqlCommand weather its returning values

if not check the column name and table name


if all this are right then check cataloge name in connection string means ur database name


这篇关于arraylist组合框中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆