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
R.D Ip
NA
76
8.3k
how to fetch statename based on country
Feb 27 2021 5:33 AM
I am working on windows form application c sharp
I am trying to fetch statename based on country in combobox
now I am stuck and my logic is not work,which place need to correction
first I fetch a country name in combobox successfully
now I am trying to fetch statename based on country but my logic is not work
sp : load country
sp : load state based on country
code:
private
void
Form1_Load_1(
object
sender, EventArgs e) //load country successfully in combobox
{
cnnString.Open();
SqlCommand cmd =
new
SqlCommand(
"sp_LoadCountry"
, cnnString);
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt =
new
DataTable();
dt.Columns.Add(
"countryid"
);
dt.Columns.Add(
"countryname"
);
dt.Load(reader);
countrycomboBox.ValueMember =
"countryid"
;
countrycomboBox.DisplayMember =
"countryname"
;
countrycomboBox.DataSource = dt;
cnnString.Close();
}
private
void
countrycomboBox_SelectedIndexChanged(
object
sender, EventArgs e) //here I am stuck state not load based on country
{
SqlCommand cmd =
new
SqlCommand(
"sp_LoadStateBaseOnCountry"
, cnnString);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"countryid"
,countrycomboBox.Items.IndexOf(cmd));
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
da.Fill(dt);
statecomboBox.ValueMember =
"stateid"
;
statecomboBox.DisplayMember =
"statename"
;
statecomboBox.DataSource = dt;
}
output:
now I am stuck in logic need help
Reply
Answers (
11
)
How to destroy an existing jQuery table on an ASP.net MVC view and the
Identity Server 4