Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 2nd, 2012, 02:07 AM
Registered User
 
Join Date: Aug 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dababy Send a message via Yahoo to dababy
Default Dropdown list not retrieving data from the database.

My code below does not display any err msg but it is not displaying the desired result. I am querying a database using a dropdown list control and I want the result to display on specified textboxes.


protected void stateList_SelectedIndexChanged(object sender, EventArgs e)
{

sqlquerypopulation.SelectCommandType = SqlDataSourceCommandType.Text;
String qry = "select Males,Females,Bothsexes,Landsize from Population where LGA = '"+ stateList.SelectedItem.Value.ToString()+"'";
System.Data.SqlClient.SqlConnection myCon = new System.Data.SqlClient.SqlConnection("server=BANCAS S\\SQLEXPRESS;database=Ruralconnect;uid=sa;pwd=");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(qry,myCon);
myCon.Open();
System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read()) {
txtpopulate.Text = dr[0].ToString ();
male.Text = dr[1].ToString ();
fmale.Text = dr [2].ToString ();
bsexes.Text = dr [3].ToString ();
landsize.Text = dr[4].ToString ();

}
dr.Close();
myCon.Close();


}





Similar Threads
Thread Thread Starter Forum Replies Last Post
My Dropdown List not inserting selected value into database. dababy ASP.NET 4 General Discussion 0 May 18th, 2012 08:14 AM
adding Dropdown list Items from SQLSERVER 2005 database biswa Pro VB Databases 1 October 23rd, 2009 10:46 AM
Data from Dropdown List to TextBox caterpillar General .NET 1 July 10th, 2006 06:05 AM
Retrieving the list of tables from a database [email protected] J2EE 0 February 2nd, 2005 09:54 PM
Retrieving list of tables inside a database... vb_developer SQL Server ASP 6 September 13th, 2004 10:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.