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
Rashid Khan
NA
159
0
DropDownList fill from database
Feb 11 2010 2:54 AM
i m trying to fill dropdown list from database but i m facing this error
"
The SelectCommand property has not been initialized before calling 'Fill'"
this is my code
please help me out , where i m making mistake
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection datacon = new SqlConnection(ConfigurationManager.ConnectionStrings["MyLink"].ConnectionString);
datacon.Open();
SqlCommand datacmd = new SqlCommand("usp_SelectAllDepartment",datacon);
datacmd.CommandType = CommandType.StoredProcedure;
datacmd.Parameters.AddWithValue("@deptId", 0);
DataSet ds = new DataSet();
SqlDataAdapter adpt = new SqlDataAdapter();
adpt.Fill(ds);
ddlDept.DataSource = ds;
ddlDept.DataTextField = "DeptName";
ddlDept.DataValueField = "DeptId";
ddlDept.DataBind();
datacon.Close();
}
}
thanks in advance
Reply
Answers (
5
)
datagrid view
Installation