OsirisJa
asked on
Help with getting info from a SQL Server 2005 database in VB.NET 2005
I am using SQL Server to store information in my program. How can I access the database and load up some variables into variables?
I have this section of the code already:
Dim conn As New System.Data.SqlClient.SqlC onnection( "Data Source=.\SQLEXPRESS;Attach DbFilename =|DataDire ctory|\Pay roll.mdf;I ntegrated Security=True;User Instance=True")
Thank you very much in advance
I have this section of the code already:
Dim conn As New System.Data.SqlClient.SqlC
Thank you very much in advance
ASKER
How do I get information from teh database loaded into variables
eg
var1 = FirstName
var2 = LastName
with firstname and lastname being informatyion in the database
eg
var1 = FirstName
var2 = LastName
with firstname and lastname being informatyion in the database
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so very much!
You can get your data into a DataTable using the following
Dim conn As New System.Data.SqlClient.SqlC
Dim objDataAdapter As New SqlDataAdapter("SELECT * FROM MY_TABLE", conn)
Dim objDataTable As New DataTable
objDataAdapter.Fill(objDat
You could then use the DataTable however you need to within your application. For example you could use it as the datasource on a DataGridView:
dataGridView1.DataSource = objDataTable
Hope this helps get you started.
Cheers
Nick