toolstripcombobox 绑定数据问题

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace BDTC_SysTem
{
    //
    //填充各种Combbox选择项工具,取到SQL语句,输出对应内容
    //
    public class FillCombboxClass
    {
       // protected static string connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
        protected static string connectionString = Properties.Settings.Default.bdtcConnectionString;
        
        public FillCombboxClass()
        {
            // TODO: Complete member initialization
        }
       
        
        public static DataTable SelectContent( string SQLString)
        {
            DataTable dt = null;
            using(SqlConnection conn=new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand(SQLString, conn)) 
                {
                    try
                    {
                        conn.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader != null && reader.HasRows)
                        {
                            dt = new DataTable();
                            dt.Load(reader);
                        }
                        return dt;
                    }
                    catch (System.Data.SqlClient.SqlException e)
                    {
                        conn.Close();
                        throw new Exception(e.Message);
                    }
                   
                     
                }
            }
            
        }

       
    }
    
}

下面是绑定到控件。

namespace BDTC_SysTem
{
    public partial class frmProductionShow : Form
    {
        public frmProductionShow()
        {
            InitializeComponent();
        }

        private void pro_ProductionTableBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.pro_ProductionTableBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.bdtcDataSet);

        }

        private void frmProductionShow_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“bdtcDataSet.Pro_FactoryTable”中。您可以根据需要移动或删除它。
            this.pro_FactoryTableTableAdapter.Fill(this.bdtcDataSet.Pro_FactoryTable);
            // TODO: 这行代码将数据加载到表“bdtcDataSet.Pro_ClassTable”中。您可以根据需要移动或删除它。
            this.pro_ClassTableTableAdapter.Fill(this.bdtcDataSet.Pro_ClassTable);
            // TODO: 这行代码将数据加载到表“bdtcDataSet.Pro_ProductionTable”中。您可以根据需要移动或删除它。
            this.pro_ProductionTableTableAdapter.Fill(this.bdtcDataSet.Pro_ProductionTable);
            try
            {
                FillSelectCombbox();
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message);
            }

        }

        private void FillSelectCombbox()
        {
            string strSql = "Select proclassid,proclassname from pro_classTable Where ProClassFather=0 order by proclassid ";
            MessageBox.Show(strSql);
            DataTable ds = FillCombboxClass.SelectContent(strSql);
            CombboxProClassSearch.ComboBox.DataSource = ds;
            CombboxProClassSearch.ComboBox.DisplayMember = ds.Columns[1].ColumnName;
            CombboxProClassSearch.ComboBox.ValueMember = ds.Columns[0].ColumnName;
            

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            string ProductionName, ProductionPinYin;
            if ((TextProductionNameSearch.Text!=string.Empty) || (TextPinYinSearch.Text!=string.Empty) || (CombboxProClassSearch.SelectedIndex != -1))
            {
                
                if (TextProductionNameSearch.Text != string.Empty) { ProductionName = TextProductionNameSearch.Text; } else { ProductionName = DBNull.Value.ToString(); }
                if (TextPinYinSearch.Text != string.Empty) ProductionPinYin = TextPinYinSearch.Text; else ProductionPinYin = DBNull.Value.ToString();
                this.pro_ProductionTableTableAdapter.FillByNPC(this.bdtcDataSet.Pro_ProductionTable, ProductionName, ProductionPinYin, int.Parse(CombboxProClassSearch.ComboBox.SelectedValue.ToString()));
            
            }
        }
               
    }
}

附上在论坛上的链接

http://topic.csdn.net/u/20120718/10/0de1b9ec-8f3c-44bf-86d0-8dd0221a3ae0.html?4631

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值