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
Ron Aricha
1.7k
52
2.2k
Bind sql data source to dropdownlist
Dec 10 2018 4:11 AM
private void fillExamList()
{
string selectExamination = "SELECT ExamCode, ExamType + ', ' + ExamDate AS ExamList FROM Examination WHERE PatientID = " + txtSearchID.Text + "";
SqlDataAdapter da = new SqlDataAdapter(selectExamination, conn);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds);
foreach (DataRow dr in ds.Tables["Table"].Rows)
{
if (dr["ExamType"].ToString() == "0")
{
dr["ExamType"] = "Yes";
}
}
ddlExamList.DataValueField = "ExamCode";
ddlExamList.DataTextField = "ExamList";
ddlExamList.DataSource = ds;
ddlExamList.DataBind();
ddlExamList.Items.Insert(0, new ListItem("Select...", "0"));
}
catch (Exception ex)
{
ErrorHandling(ex.ToString());
}
finally
{
conn.Close();
}
}
When I run this code I get an error that says:
System.ArgumentException: Column 'ExamType' does not belong to table Table.
at System.Data.DataRow.GetDataColumn(String columnName)
at System.Data.DataRow.get_Item(String columnName)
at BindData.Default.fillExamList() in C:\Users\Ron\Documents\Visual Studio 2017\Projects\BindData\BindData\Default.aspx.cs:line xxx
How can I fix it?
Reply
Answers (
4
)
When do we use Document.Ready over Onload Function or may be
hide name of controller,action from url