Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi , i have a WebApp which contains 2 textboxes (txtName and txtID). txtName is populated from a queryString i.e.
C#
String Brkc = Request.QueryString["Name"];
txtName.Text = Name;


I have a stored procedure to find the ID from the database for whichever name is populated in the textbox.

The problem is , i want to populate the txtID textbox with the ID from the text that is in txtName.

thanks.
Posted
Comments
CodingLover 2-Sep-11 4:01am    
You mean that on content changed of the txtName you need to find the ID and fill?
Rico_ 2-Sep-11 4:05am    
yes

0. Open connection.
1. Create command with query "select id from table where name = '" + txtName.Text +"'" or your procedure.
2. Use String id = cmd.ExecuteScalar();
3. Use id wherever you want txtID.Text = id;
 
Share this answer
 
v3
Comments
DominicZA 2-Sep-11 4:18am    
No, I dont think this is right. He already has the proc to get the ID, we wants to know where!
Rico_ 2-Sep-11 4:24am    
Hi , i already have the ID. i need to populate the txtID textbox with the ID.
How many names are you using here? You could create a static Dictionary in a Cache.cs file. Just update the dictionary when another user is created, this will take a load off the DB, so your Cache.cs would have the following:

C#
private Dictionary<string,> _users = null;
public Dictionary<string,> Users
{
get
{
     if (_users == null)
         MethodThatPopulatesUsers();
     return _users;
}
}

public void ClearUserCache()
{
     _users = null;
}

private void MethodThatPopulatesUsers()
{
    //Make the call to the DB and populate the dictionary with the username as the Key and the ID as the value. 
}


Then, where your textbox is, on the OnTextChanged event just have:

C#
if (Cache.Users.ContainsKey(txtTextbox1.Text))
    txtTextbox2.Text = Cache.Users[txtTextbox1.Text];
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900