Re: Populate Data from SQL
Quote:
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.
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.
Re: Populate Data from SQL
You didn't address this:
Quote:
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.
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.
Re: Populate Data from SQL
As for the data it's just a nvarchar(50) field for the employee name.
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