Help me with the query strings.
-
Hi I am developing a project which involves query strings. I want when user selects a city from a drop down list it has to be passed to the next page and show the values from the database in the gridview based on the value selected in drop downlist. My code is : protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e) { string url = "Cityschedules.aspx?City="+ ddlCity.SelectedItem.Text; Response.Redirect(url); } When the user Enters say "New Delhi" It shud show the all the values where city is "New Delhi" In Cityschedules.aspx protected void Page_Load(object sender, EventArgs e) { try { string strSQLconnection = "Data Source=SHASHI-56B0C28E\\SQLEXPRESS;Initial Catalog=Project_Airways;Persist Security Info=True;User ID=sa;Password=sql2005"; SqlConnection sqlConnection = new SqlConnection(strSQLconnection); SqlCommand sqlCommand = new SqlCommand("SELECT * FROM [ARS_Schedules] WHERE ([Origin_Place] = '@Origin_Place1')", sqlConnection); sqlConnection.Open(); string Origin_Place1 = Request.QueryString["City"]; SqlDataReader reader = sqlCommand.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); } catch (SqlException se) { Console.WriteLine(se.Message); } finally { sqlConnection.close(); } } I am getting exceprion "{"The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found."}" Also when this exception is solved i am getting another exception saying "Must declare scalar variable @origin_Place1" Thanks in advance regards shashi
-
Hi I am developing a project which involves query strings. I want when user selects a city from a drop down list it has to be passed to the next page and show the values from the database in the gridview based on the value selected in drop downlist. My code is : protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e) { string url = "Cityschedules.aspx?City="+ ddlCity.SelectedItem.Text; Response.Redirect(url); } When the user Enters say "New Delhi" It shud show the all the values where city is "New Delhi" In Cityschedules.aspx protected void Page_Load(object sender, EventArgs e) { try { string strSQLconnection = "Data Source=SHASHI-56B0C28E\\SQLEXPRESS;Initial Catalog=Project_Airways;Persist Security Info=True;User ID=sa;Password=sql2005"; SqlConnection sqlConnection = new SqlConnection(strSQLconnection); SqlCommand sqlCommand = new SqlCommand("SELECT * FROM [ARS_Schedules] WHERE ([Origin_Place] = '@Origin_Place1')", sqlConnection); sqlConnection.Open(); string Origin_Place1 = Request.QueryString["City"]; SqlDataReader reader = sqlCommand.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); } catch (SqlException se) { Console.WriteLine(se.Message); } finally { sqlConnection.close(); } } I am getting exceprion "{"The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found."}" Also when this exception is solved i am getting another exception saying "Must declare scalar variable @origin_Place1" Thanks in advance regards shashi
shashi_code wrote:
"{"The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found."}"
Check GridView1 property Datasource on Design if it has set SqlDataSource1 as datasourceid, if it has then remove it.
SqlCommand sqlCommand = new SqlCommand(" declare @Origin_Place1 as varchar (500) set @Origin_Place1='"+Request.QueryString["City"]+"' SELECT * FROM [ARS_Schedules] WHERE ([Origin_Place] = @Origin_Place1)", sqlConnection);
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
-
Hi I am developing a project which involves query strings. I want when user selects a city from a drop down list it has to be passed to the next page and show the values from the database in the gridview based on the value selected in drop downlist. My code is : protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e) { string url = "Cityschedules.aspx?City="+ ddlCity.SelectedItem.Text; Response.Redirect(url); } When the user Enters say "New Delhi" It shud show the all the values where city is "New Delhi" In Cityschedules.aspx protected void Page_Load(object sender, EventArgs e) { try { string strSQLconnection = "Data Source=SHASHI-56B0C28E\\SQLEXPRESS;Initial Catalog=Project_Airways;Persist Security Info=True;User ID=sa;Password=sql2005"; SqlConnection sqlConnection = new SqlConnection(strSQLconnection); SqlCommand sqlCommand = new SqlCommand("SELECT * FROM [ARS_Schedules] WHERE ([Origin_Place] = '@Origin_Place1')", sqlConnection); sqlConnection.Open(); string Origin_Place1 = Request.QueryString["City"]; SqlDataReader reader = sqlCommand.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); } catch (SqlException se) { Console.WriteLine(se.Message); } finally { sqlConnection.close(); } } I am getting exceprion "{"The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found."}" Also when this exception is solved i am getting another exception saying "Must declare scalar variable @origin_Place1" Thanks in advance regards shashi
hi, try c# forum, you will get more posts By the way, can´t you do the sql in sql server and trigger it in c#? Good Luck :omg:
-
Hi I am developing a project which involves query strings. I want when user selects a city from a drop down list it has to be passed to the next page and show the values from the database in the gridview based on the value selected in drop downlist. My code is : protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e) { string url = "Cityschedules.aspx?City="+ ddlCity.SelectedItem.Text; Response.Redirect(url); } When the user Enters say "New Delhi" It shud show the all the values where city is "New Delhi" In Cityschedules.aspx protected void Page_Load(object sender, EventArgs e) { try { string strSQLconnection = "Data Source=SHASHI-56B0C28E\\SQLEXPRESS;Initial Catalog=Project_Airways;Persist Security Info=True;User ID=sa;Password=sql2005"; SqlConnection sqlConnection = new SqlConnection(strSQLconnection); SqlCommand sqlCommand = new SqlCommand("SELECT * FROM [ARS_Schedules] WHERE ([Origin_Place] = '@Origin_Place1')", sqlConnection); sqlConnection.Open(); string Origin_Place1 = Request.QueryString["City"]; SqlDataReader reader = sqlCommand.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); } catch (SqlException se) { Console.WriteLine(se.Message); } finally { sqlConnection.close(); } } I am getting exceprion "{"The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found."}" Also when this exception is solved i am getting another exception saying "Must declare scalar variable @origin_Place1" Thanks in advance regards shashi
well u can use a session variable instead of request.city ... make a session variable and store the value of ur drop down in it on page load retrieve the value n then query the Database... Example make a session variable in global.asax Session["City"]=""; then store the value of dropdown in session i.e session["City=dropdownlist1.selectedvalue"]; then redirect to other url on page load string query="SELECT * FROM [ARS_Schedules] WHERE ([Origin_Place] = "+session["City"].ToString()+""; hope this will work for u... :) take care remember me in ur prayers FEEAMANALLAH
AHSAN SARFRAZ UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA PAKISTAN COMPUTER SYSTEM ENGINEERING DEPARTEMENT
-
shashi_code wrote:
"{"The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'SqlDataSource1' could not be found."}"
Check GridView1 property Datasource on Design if it has set SqlDataSource1 as datasourceid, if it has then remove it.
SqlCommand sqlCommand = new SqlCommand(" declare @Origin_Place1 as varchar (500) set @Origin_Place1='"+Request.QueryString["City"]+"' SELECT * FROM [ARS_Schedules] WHERE ([Origin_Place] = @Origin_Place1)", sqlConnection);
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
I was getting the same error. Ur soultion worked. Thanks a lot. Meenal Ronghe.