TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bineesh Viswanath
NA
1k
775.4k
Retrieve Data from Database into comboBox in C#
Oct 2 2013 8:39 AM
Sir, I am doing a program of comboBox filling from database.
I need your help in suggesting a higher C# standard code for this function.
Please go through all the code. I need a capsulized code and a higher standard code.
please tell me how this code change to standard and precise.
Here the Code I worked with:-
1) SQL Table:-
empId numeric(18, 0) Unchecked
empName varchar(20) Unchecked
Age int Unchecked
address varchar(MAX) Unchecked
department varchar(20) Unchecked
salary int Unchecked Unchecked
2) SQL Stored Procedure:-
ALTER PROCEDURE employeeViewAll
AS
SELECT empName, Age, address, department, salary
FROM tbl_Employee RETURN
3) Class SP function:-
public DataTable EmployeeViewAll()
{
try
{
DataTable dtbl = new DataTable();
SqlDataAdapter SqlDa = new SqlDataAdapter("employeeViewAll", sqlCon);
SqlDa.SelectCommand.CommandType = CommandType.StoredProcedure;
SqlDa.Fill(dtbl);
return dtbl;
}
catch (Exception)
{
throw;
}
}
4) form.cs Code:-
public void ComboFill()
{
DataTable d = new DataTable();
eSP SP = new eSP();
d = SP.EmployeeViewAll();
comboBox1.DataSource = d;
comboBox1.DisplayMember = "department";
}
5) Finally, I called the function in form load:-
private void frmTest_Load(object sender, EventArgs e)
{
ComboFill();
}
Please help me in this topic.
Reply
Answers (
5
)
Auto generate Number in Winform TextBox
Single Tier 2-Tier and 3-Tier Architecture in C#