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
Israel
702
1.3k
216.4k
How to make filter into combobox from Database properly
Apr 19 2017 3:40 AM
Hi!
I have database with two column: "
name
" and "
mobile
". I need to filter for example on the column "
mobile
" a specific number. Then into my combobox should appear all names affected by the same mobile number only. But the code I wrote doesnt obey. Its point the error here:
SqlDataReader sdr = comm.ExecuteReader();
private void cbxName_SelectedIndexChanged(object sender, EventArgs e)
{
conn.Open();
//comm = new SqlCommand("SELECT DISTINCT nom_complet FROM church", conn);
comm = new SqlCommand("SELECT name FROM church where mobile like('" + "txtMobileNumber.Text" + "%')");
SqlDataReader sdr = comm.ExecuteReader();
//Its point here as error
DataTable dt = new DataTable();
dt.Load(sdr);
cbxReadNomFlashMessage.DisplayMember = "name";
cbxReadNomFlashMessage.DroppedDown = true;
List<string> list = new List<string>();
foreach (DataRow row in dt.Rows)
{
list.Add(row.Field<string>("name"));
}
this.cbxReadNomFlashMessage.Items.AddRange(list.ToArray<string>());
cbxReadNomFlashMessage.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
cbxReadNomFlashMessage.AutoCompleteSource = AutoCompleteSource.ListItems;
conn.Close();
///////////////////////doesnt allow repeat item in combobox////////////
for (int i = 0; i < cbxReadNomFlashMessage.Items.Count; i++)
{
for (int y = 0; y < cbxReadNomFlashMessage.Items.Count; y++)
{
if (y != i && cbxReadNomFlashMessage.Items[i].ToString() == cbxReadNomFlashMessage.Items[y].ToString())
{
cbxReadNomFlashMessage.Items.RemoveAt(i);
break;
}
}
}
Reply
Answers (
5
)
How to give validation for accountno and BSB no in MVC
Checkbox values are not binding from db in mvc