We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Load Record by value in textbox

Andrew Stillwell
on
Medium Priority
257 Views
Last Modified: 2012-08-13
I need to be able to load a record into muliple textboxes by entering a value into one of the textboxes.

How can I do this?
Comment
Watch Question

Commented:
i think you have to be more detailed on this...

1. load a record from where?? - a data base or flat file or dataset or xml or what??
2. do you want to enter a value, press button and trigger the event, or you want start typing and as soon as something is typed, you want to trigger your event, or you want to type something as soon as focus leaves the textobx, you want to trigger your event.

regs,
yurich

Author

Commented:
1. load a record from where?? - a data base or flat file or dataset or xml or what??

From an Access database

2. do you want to enter a value, press button and trigger the event, or you want start typing and as soon as something is typed, you want to trigger your event, or you want to type something as soon as focus leaves the textobx, you want to trigger your event.

As soon as a value is entered I want it to retrieve the values for each textbox
Commented:
there're really several approaches, one of them:

suggesting that you want to do it in the OnButton_Click method of the button after all data is entered in all texboxes.

// add this directive to all using directive
using System.Data.OleDbClient;
...

// that's in your button handling event
OleDbConnection conn = new OleDbConnection();
// connection string can of course be different
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb";
conn.Open();

OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM table_name WHERE something = '" + txtCriterion.Text + "'";
OleDbDataReader dreader = cmd.ExecuteReader();

if( dreader.Read())
{
  txtValue1.Text = dreader[ "column_name1" ].ToString();
  txtValue2.Text = dreader[ "column_name2" ].ToString();
}

dreader.Close();
conn.Close();

it should give you a go,
good luck,
yurich

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.