Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i write the code to fill combobox with database value. my code is working correctly if this code written on presentation layer. But i want to written this code on data layer. i have 3 project in my solution (UI, BLL, DAL). i want this code in DAL and then call in UI with the help of BLL. how to do that. please help me. here is my code.

How to convert my code into 3 tier architecture.

What I have tried:

C#
using (SQLiteConnection conn = new SQLiteConnection(EmployeeComboFills.ecbconn()))
            {
                string CommandText = "SELECT Name FROM User";
                using (SQLiteCommand cmd = new SQLiteCommand(CommandText, conn))
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    DataTable dt = new DataTable();
                    SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
                    da.Fill(dt);
                    foreach (DataRow dr in dt.Rows)
                    {
                        CELD_employeename.Items.Add(dr["Name"].ToString());
                    }
                }
            }
Posted
Updated 12-Jan-19 0:08am

Put that code in a function in the data layer but don't do the "foreach", just have that method return "dt". The business layer will just be a single line that will call the function from the data layer and return the result. The presentation layer will then get the datatable from the business layer and it fill do the "foreach" to add the items to CELD_employeename
 
Share this answer
 
Comments
Member 14115523 11-Jan-19 13:05pm    
but how to write code on presentation layer. sorry for stupid question i'm newbie in c#.
Try this.

C#
void List(){
SQLConnection.MsSql con = new SQLConnection.MsSql();
                System.Data.SqlClient.SqlConnection objConnd = new System.Data.SqlClient.SqlConnection();
                System.Data.SqlClient.SqlDataAdapter dtAdapterd = new System.Data.SqlClient.SqlDataAdapter();
                DataTable dtd = new DataTable();
                String strConnString = con.conn;
                objConnd = new System.Data.SqlClient.SqlConnection(strConnString);
                objConnd.Open();
                String strSQL;
                strSQL = "SELECT Name FROM User";
                dtAdapterd = new System.Data.SqlClient.SqlDataAdapter(strSQL, objConnd);
                dtAdapterd.Fill(dtd);
                dtAdapterd = null;
                objConnd.Close();
                objConnd = null;
                this.comboboxFilter.DataSource = dtd;
                this.comboboxFilter.ValueMember = "Name";
                this.comboboxFilter.DisplayMember = "Name";
                this.comboboxFilter.SelectedIndex = -1;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900