|
-
Apr 23rd, 2013, 08:14 PM
#1
Thread Starter
New Member
Populate Data from SQL
What I would like to do is have data populate in a Textbox2 based on data in Textbox1. Now the data it will be populating is in a SQL table and I want it to Pull data from Column B by looking for the Data from the Column A using whats in Textbox1. The other kicker is Textbox1 is not part of the table I am pulling the data for Textbox2.
-
Apr 23rd, 2013, 09:07 PM
#2
Re: Populate Data from SQL
 Originally Posted by RWJ_2006
The other kicker is Textbox1 is not part of the table I am pulling the data for Textbox2.
There must be some sort of relationship between them but if you keep it a secret then we can't provide a specific solution.
I think that the first consideration is how much data there is in total. If there's not too much then you'd probably just retrieve it all into a DataTable and then work with it locally. If there is quite a bit then you'd probably want to query the database each time you needed new data.
-
Apr 23rd, 2013, 09:10 PM
#3
Thread Starter
New Member
Re: Populate Data from SQL
The data in Textbox1 is the same as in Column A just stored in a different table. Column A is an ID Number and Column B is a name.
-
Apr 23rd, 2013, 09:36 PM
#4
Re: Populate Data from SQL
You didn't address this:
 Originally Posted by jmcilhinney
I think that the first consideration is how much data there is in total. If there's not too much then you'd probably just retrieve it all into a DataTable and then work with it locally. If there is quite a bit then you'd probably want to query the database each time you needed new data.
Also, how is the data getting into TextBox1? If the user is entering it then it's not coming from any table but rather it's user input. If it is actually coming from another table then how does it get into TextBox1? What you're asking for could be achieved in various different ways but the best way depends on specific details that you haven't provided. I have a suspicion of exactly what's going on but it's not something that I should have to guess. Are these two Textboxes the only controls involved or are there others? If there are others then exactly what do they contain and where does the data come from? We need a FULL and CLEAR description of the problem to be sure that we are providing a relevant and optimal solution. If we guess then we might get it right or we might end up just wasting our time and yours.
-
Apr 23rd, 2013, 10:14 PM
#5
Thread Starter
New Member
Re: Populate Data from SQL
Sorry I am very new at this. The form I am using is to view and modify maintenance work orders. When the work order is created the employee creating it enters there ID. What I want is when Maint. opens this form the employees name populates on the form next to the text box with there ID. The initial data is entered on another screen. Textbox1 is not editable it's just pulling the data from the SQL column in the work order table. The table I want to use to cross reference and pull the name is the employee table. I already have the work order edit form pulling up all the data from the work order table using the SQL system in VB 2008. I just want it to cross reference the employee ID and display the name.
-
Apr 23rd, 2013, 10:18 PM
#6
Thread Starter
New Member
Re: Populate Data from SQL
As for the data it's just a nvarchar(50) field for the employee name.
-
Apr 23rd, 2013, 10:30 PM
#7
Re: Populate Data from SQL
try this:
Code:
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlConnection("connection string")
Dim cmd As New SqlCommand("SELECT [Name] FROM employee WHERE employeeID=@employeeID", conn)
'which of these 2 parameters you use depends on employeeID field datatype
cmd.Parameters.Add("@employeeID", SqlDbType.Int).Value = CInt(textbox1.text)
'cmd.Parameters.Add("@employeeID", SqlDbType.VarChar).Value = textbox1.text
Dim o As Object = cmd.ExecuteScalar
TextBox2.text = If(o IsNot Nothing, o.ToString, "")
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|