Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / June 2008



Tip: Looking for answers? Try searching our database.

Help with displaying data in datagrid view on a new form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Zaur Bahramov - 09 Jun 2008 19:58 GMT
Hi!

Am writing a new application that would work with the database. The
application is pretty simple. But, since I'm a newbie in vb I'm having
problems with getting results of the SELECT statement into a window.

i use an AdventureWorksLT database. I need somehow bring the result of the
SELECT statement against one of three tables into a new form. I have two
forms so far. First, main form, where I need to select table and execute a
query, and another (so far empty) form, where I need to print out results in
a datagrid view.

What do I need to add after sqlStatement.ExecuteReader() to open a new frame
with the datagrid and correct output. And how do I select which column to
show if any of three tables are opened?

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click

lblStatus.Text = "Database Status: closed"

' qui selezziono la connessione a SQL.

' #####################################################

Dim connectionString As String = _

"Data Source = WEBSRV1\SQLEXPRESS;" & _

"Initial Catalog = adventureWorksLT; Integrated Security = True"

Dim adventureWorks As New SqlClient.SqlConnection(connectionString)

adventureWorks.Open()

lblStatus.Text = "Database Status: opened"

' ############### FINE SELEZIONA STATEMENT #############

' qui selezziono la tabella sul SQL dove vado ad inserire i comandi.

' #####################################################

Dim selectedTable As String

If rdbAddress.Checked Then

selectedTable = "[SalesLT].[Address]"

lblPrompt.Text = selectedTable

ElseIf rdbCustomer.Checked Then

selectedTable = "[SalesLT].[Customer]"

lblPrompt.Text = selectedTable

ElseIf rdbProduct.Checked Then

selectedTable = "[SalesLT].[Product]"

lblPrompt.Text = selectedTable

Else

MsgBox("Error! Devi selezzionare la tabella!")

End If

' ############### FINE SELEZIONA TABELLA #############

' qui selezziono lo Statement da girare.

' #####################################################

Dim selectedStatement As String

If rdbSelect.Checked Then

selectedStatement = "SELECT"

lblPrompt.Text &= " Method: " & selectedStatement

Dim sqlStatement As New SqlClient.SqlCommand( _

"SELECT * FROM " & selectedTable, adventureWorks)

Dim dataresults As SqlClient.SqlDataReader = _

sqlStatement.ExecuteReader()

ElseIf rdbUpdate.Checked Then

selectedStatement = "UPDATE"

lblPrompt.Text &= " Method: " & selectedStatement

ElseIf rdbTruncate.Checked Then

selectedStatement = "TRUNCATE"

lblPrompt.Text &= " Method: " & selectedStatement

End If

' ############### FINE SELEZIONA STATEMENT #############
Ralph - 09 Jun 2008 21:10 GMT
> Hi!
>
[quoted text clipped - 11 lines]
> with the datagrid and correct output. And how do I select which column to
> show if any of three tables are opened?

You are using some version of Visual Basic.Net. This newsgroup is populated
mostly by users of 'Classic' VB (VB6 and lower). You are better off posting
to a 'dotNet' newsgroup (they will have "dotNet" in the title).

-ralph
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.