ProgrammingMSAccess.com

Learn about Developers Group
Join Developers Group
Order SPAM Blocker
Free Stuff
Guest Book
.NET Resources
SQL Server Resources
Favorites
Technical Support
Books & DVDs by Webmaster
Articles, tutorials, & more
FAQs
Product Reviews
Samples
Prior Newsletters
Contact Us
Home
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

This Button Click event procedure assigns a t-sql statement to a sqldataadapter and invokes the fill method to populate a dataset.  While this sample uses dynamic t-sql, you can follow the same approach with static t-sql or by using parameters for the T-SQL.  aFTER CREATING A DATATABLE IN THE DATASET WITH THE SQLDATAADAPTER, THE CODE DISPLAYS THE NAME FOR THE DATATABLE AND A COLUMN WITHIN IT.

Private Sub Button2_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs)

'Declare and instantiate a new dataset
Dim das1 As New DataSet

'Declare a couple of strings for a
'DataAdapter
Dim str1 As String = TextBox1.Text
Dim str2 As String = "SELECT * " & _
"FROM Customers " & _
"WHERE CustomerID = '" & str1 & "'"
Dim DACustomer As SqlClient.SqlDataAdapter = _
New SqlClient.SqlDataAdapter(str2, _
MyConnection)

'Fill the das1 from DACustomer
DACustomer.Fill(das1, "Customers")

'Display the name of the DataTable
'within das1, and the name of the first
'column in the DataTable
Console.WriteLine(das1.Tables(0). _
TableName)
Console.WriteLine(das1.Tables(0). _
Columns(0).ColumnName)

End Sub

 

Learn more about VB.NET programming from either Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .NET or Programming Microsoft Visual Basic .NET for Microsoft Access Databases.

Copyright 2003 CAB, Inc. All rights reserved. Republication or redistribution of CAB, Inc. content, including by framing or similar means, is expressly prohibited without the prior written consent of CAB, Inc. CAB, Inc. shall not be liable for any errors in the content, or for any actions taken in reliance thereon.