| Author |
Topic |
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 04:11:09
|
| can you pls help me with a stored procedure,i have to dropdownlist i want to first select the first dropdown them the information that belongs to that name i select be shown in the second dropdownlist,like i have provinces if i select province in the first dropdown, the city that belongs to that province will be shown on the second dropdownlist.Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-10 : 04:13:10
|
what's the problem you are facing ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-09-10 : 04:20:45
|
| Thats not a stored procedure's funcntion.You should look into ajax, and its relatively easy to use in visual studio. Though you will need to create a recordset to retrieve your data. To get that done, you could create a data connection class. |
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 04:30:16
|
How can i do it because i tryed a lot but it not working,it only take the last recordquote: Originally posted by afrika Thats not a stored procedure's funcntion.You should look into ajax, and its relatively easy to use in visual studio. Though you will need to create a recordset to retrieve your data. To get that done, you could create a data connection class.
|
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-09-10 : 04:33:52
|
| What frontend are you using to display ? .net ?If thats the case, this post should have posted in the .net forum.post your script here ? |
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 04:37:12
|
is that when i try to retrieve the information that related to the dropdown i selected it only give me the information of the last record in my dropdownlistquote: Originally posted by khtan what's the problem you are facing ? KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-09-10 : 04:39:59
|
quote: Originally posted by Mpilo is that when i try to retrieve the information that related to the dropdown i selected it only give me the information of the last record in my dropdownlistquote: Originally posted by khtan what's the problem you are facing ? KH[spoiler]Time is always against us[/spoiler]
Post your script here |
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 04:43:02
|
i'm using .net and for database i use sqlserver , i think we can solve this with stored procedure here is my stored procedureSET QUOTED_IDENTIFIER ONGOALTER procedure [dbo].[cityselects]@CityName varchar(30)=''Asdeclare @Cities varchar(30)if exists (select ProvinceDataName from ProvinceData)set @Cities=''select @Cities=ProvinceDataName from ProvinceDatabeginselect CityName from City,provincedatawhere City.provincedatano=provincedata.provincedatano and provincedata.provincedataname=@CitiesEndbut it take the max(provincedataname)quote: Originally posted by afrika What frontend are you using to display ? .net ?If thats the case, this post should have posted in the .net forum.post your script here ?
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-10 : 04:47:05
|
quote: if exists (select ProvinceDataName from ProvinceData)set @Cities=''select @Cities=ProvinceDataName from ProvinceData
what are you trying to do with these statements ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 04:50:22
|
trying to check the selected itemso i can continue to select the city that belongs to that province that is seletedquote: Originally posted by khtan
quote: if exists (select ProvinceDataName from ProvinceData)set @Cities=''select @Cities=ProvinceDataName from ProvinceData
what are you trying to do with these statements ? KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-10 : 04:50:35
|
quote: Originally posted by Mpilo can you pls help me with a stored procedure,i have to dropdownlist i want to first select the first dropdown them the information that belongs to that name i select be shown in the second dropdownlist,like i have provinces if i select province in the first dropdown, the city that belongs to that province will be shown on the second dropdownlist.Thanks
maybe this is what you want ? You pass in the selected provice name from 1st drop down into the Stored Procedure and it returns the cityname ?ALTER PROCEDURE [dbo].[cityselects] @province varchar(30)=''ASBEGIN SELECT CityName FROM City INNER JOIN provincedata ON City.provincedatano = provincedata.provincedatano WHERE provincedata.provincedataname = @provinceEND KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-09-10 : 04:51:02
|
quote: Originally posted by Mpilo but it take the max(provincedataname)
So what are you trying to sort. And what are you trying to display in your front end. I advice you post your .net script that interacts with this as well. As I said ajax could do the trick easily |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-10 : 04:54:19
|
| <<select @Cities=ProvinceDataName from ProvinceData>>If there are more than one ProvinceDataName, only the last returned would be assignedFollow khtan's queryMadhivananFailing to plan is Planning to fail |
 |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-09-10 : 04:56:59
|
| This link will provide you some insight. http://msdn.microsoft.com/en-us/library/aa581792.aspxAlso, when you are trying to populate second dropdown on index change of fisrt (province), you have to use SP mentioned by khtan and pass province selected to it. 1. Populate Province dropdown2. On index change of province dropdown, pass selected value to SP (khtan).3. Fill city dropdown with data returned from above SP.Hope this helps. also search for "master detail .net" on google. |
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 05:06:52
|
i tried this but now it doesn't output anything in the dropdownquote: Originally posted by khtan
quote: Originally posted by Mpilo can you pls help me with a stored procedure,i have to dropdownlist i want to first select the first dropdown them the information that belongs to that name i select be shown in the second dropdownlist,like i have provinces if i select province in the first dropdown, the city that belongs to that province will be shown on the second dropdownlist.Thanks
maybe this is what you want ? You pass in the selected provice name from 1st drop down into the Stored Procedure and it returns the cityname ?ALTER PROCEDURE [dbo].[cityselects] @province varchar(30)=''ASBEGIN SELECT CityName FROM City INNER JOIN provincedata ON City.provincedatano = provincedata.provincedatano WHERE provincedata.provincedataname = @provinceEND KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-10 : 05:10:38
|
| How did you execute the procedure?Did you supply parameter value?MadhivananFailing to plan is Planning to fail |
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 05:15:36
|
Maybe the problem with this is that i cal this stored procudure in the ddlCity_Onload.maybe it retrieve before i select.is this can be problem?quote: Originally posted by khtan
quote: Originally posted by Mpilo can you pls help me with a stored procedure,i have to dropdownlist i want to first select the first dropdown them the information that belongs to that name i select be shown in the second dropdownlist,like i have provinces if i select province in the first dropdown, the city that belongs to that province will be shown on the second dropdownlist.Thanks
maybe this is what you want ? You pass in the selected provice name from 1st drop down into the Stored Procedure and it returns the cityname ?ALTER PROCEDURE [dbo].[cityselects] @province varchar(30)=''ASBEGIN SELECT CityName FROM City INNER JOIN provincedata ON City.provincedatano = provincedata.provincedatano WHERE provincedata.provincedataname = @provinceEND KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-09-10 : 05:18:45
|
| I would advice you paste your .net page here |
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 05:19:09
|
Yes i did all that.quote: Originally posted by madhivanan How did you execute the procedure?Did you supply parameter value?MadhivananFailing to plan is Planning to fail
|
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 05:23:08
|
Okey i'm using three tier so here is my Data access layer: public DataTable SelectCity(string CityName) { SqlParameter p; this.Connections(); DataTable dtcity = new DataTable(); cmd = new SqlCommand("cityselects", connection); cmd.CommandType = CommandType.StoredProcedure; p = new SqlParameter("@CityName", SqlDbType.VarChar); p.Direction = ParameterDirection.Input; p.Value = CityName; cmd.Parameters.Add(p); adapter = new SqlDataAdapter(cmd); dtcity.Clear(); adapter.Fill(dtcity); cmd.ExecuteNonQuery(); this.Closeconnection(); return dtcity; }Business logic:public DataTable CitySelect() { dtCity.Clear(); return dtCity = conCity.SelectCity(CityName); }and my presentation layer : protected void ddlCityName_SelectedIndexChanged(object sender, EventArgs e) { try { if ((Convert.ToString(ddlCityName.SelectedItem)) == ("Add New City")) { Session["provincename"] = "City"; Response.Redirect("AddName.aspx"); province = 1; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }quote: Originally posted by afrika I would advice you paste your .net page here
|
 |
|
|
Mpilo
Yak Posting Veteran
52 Posts |
Posted - 2008-09-10 : 05:26:17
|
No i paste a wrong code for Presentation layer here is the correct one: protected void ddlCityName_Load(object sender, EventArgs e) { if (!IsPostBack) { dtProv = CBLL.CitySelect(); int j; bool found = false; ddlCityName.Items.Add(new ListItem("--Select City--", "")); while (found == false) { found = true; for (j = 0; j < dtProv.Rows.Count; j++) { ddlCityName.Items.Add(new ListItem(dtProv.Rows[j]["CityName"].ToString())); } } ddlCityName.Items.Add(new ListItem("Add New City")); } }quote: Originally posted by afrika I would advice you paste your .net page here
|
 |
|
|
Next Page
|