Populating a drop down list from the db

  • Thread starter Thread starter lewindha
  • Start date Start date
L

lewindha

Hey guys

I'm trying to populate a drop down list with values from a db table.
When I view the page, the drop list is empty. Here is the code:


private void populateClients()
{
string connStr = "left blank for security reasons";
sqlConnection = new SqlConnection(connStr);

sqlConnection.Open();

DataTable t_table = new DataTable();
SqlDataAdapter adapt;

string sql = "SELECT iClientID, cClientName FROM
tblAllocated_ClientID";
sqlSelectCommand1 = new SqlCommand(sql, sqlConnection);
adapt = new SqlDataAdapter(sqlSelectCommand1);
adapt.Fill(t_table);

ClientParm.DataSource = t_table;
ClientParm.DataTextField = "cClientName";
ClientParm.DataValueField = "iClientID";
ClientParm.DataBind();
ClientParm.Items.Add(new ListItem("-Select
Client-", ""));
ClientParm.SelectedValue = "";
}


I created this function and call it from the page_load function like
so:

[code:1:46adb98647]
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
if( !Page.IsPostBack )
{
populateClients();
}
}
catch(Exception ex)
{
}
}
[/code:1:46adb98647]

Can anyone tell me what I'm doing wrong, please?

Thanks

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Hello!

I am programming a cloning service (which is essential to the framework),
and am currently using a custom implementation of the ICloneable interface.
With this in mind, I am wondering if I would be better off just using the
MemberWiseClone method of the inherited base object class.

Having measured the differences in speed, the MemberWiseClone implementation
was is approx. 25% slower than the custom implementation. We were debating
this at work and some suggested that I would benefit from future
improvements in the CLR implementation.

However, as this is a critical part of the framework, I believe a 25%
degradation would make the code suffer too much. Also, I could just run the
tests again when .NET 2.0 is released at a later time and change the cloning
service implementation if necessary.

The MemberWiseClone method forwards the call to an external method. I am
interested in the details of this implementation. Is the CLR using
reflection to clone the objects?

Thanks in advance.
 
Back
Top