alaa

alaa

  • NA
  • 166
  • 85.2k

how to load multi comboboxs from diffrent table in database

Dec 8 2012 3:44 PM
how to load multi comboboxs from  diffrent table in database  
i build  a class where  i can connect database and put  my datatabell  here  it is 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Data.SqlClient;
using System.Data;


namespace SELECTComboboxCLASSES
{
    class DB
    {
        SqlConnection connet;
        SqlCommand cmd;
        SqlDataAdapter da = new SqlDataAdapter();
        DataTable dt;




                #region  connection and open it


        private void Intialize(CommandType CT, string SPSQL)  
        {
            connet = new SqlConnection();
            cmd = new SqlCommand();
            connet.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Educational System;Data Source=DREAMS";
            cmd.Connection = connet;
            cmd.CommandType = CT;
            cmd.CommandText = SPSQL;
            connet.Open();
        }


                #endregion
        #region  connection and open it


        public DataTable RunSELECT(string Select)
    {
        Intialize(CommandType.Text, Select);
        dt = new DataTable();
        dt.Load(cmd.ExecuteReader());
        connet.Close();
        return dt;
    }
    #endregion


    }// end of the class


       


}




then i make  an other  class where  i cann  run my select command and pass the value from  and  to data base 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;


namespace SELECTComboboxCLASSES
{
    class SELECTCOMBOBOX
    {
        DB getconnetion = new DB();


        public bool DropdownList1(string ValueMemberData, string DisplayMemberData)
        {
            string query = string.Format("SELECT jobid, jobname FROM Job ORDER BY jobid", ValueMemberData, DisplayMemberData);
            if (getconnetion.RunSELECT(query).Rows.Count == 1)
               
                return true;
            else
                return false;


        }


        public bool DropdownList2(string ValueMemberData, string DisplayMemberData)
        {
            string query = string.Format("SELECT Userid, username FROM User ORDER BY userid", ValueMemberData, DisplayMemberData);
            if (getconnetion.RunSELECT(query).Rows.Count == 1)


                return true;
            else
                return false;


        }


        public bool DropdownList3(string ValueMemberData, string DisplayMemberData)
        {
            string query = string.Format("SELECT Rolid, Rolname FROM Rols ORDER BY rolid", ValueMemberData, DisplayMemberData);
            if (getconnetion.RunSELECT(query).Rows.Count == 1)


                return true;
            else
                return false;


        }


    }
}




and  last  i put three  combobox where i want  it to get  data in load  how  can i  complete  this  work  please help i am  still  beginner  but  i make many trials  but  still  nothing !!!
what  is the correct one ???





Answers (3)