|
-
Apr 14th, 2011, 03:49 PM
#1
Thread Starter
New Member
Console App Help!
Hello!
I am new to vb.net, im in the middle of creating a console application that will return queries from an .sdf database and display the results in the console. My problem is i want to run a few queries one after each other but i have no idea what to do! I have done a similar app in java where I created new methods in the main code which helped but where do i go from here??
The code is as follows
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Data.SqlClient
Imports System.Data.SqlServerCe
Module Module1
Dim myConnection As SqlCeConnection
Dim Query As SqlCeCommand
Dim Duration As TimeSpan
Dim StartTime As DateTime = DateTime.Now
Sub Main()
myConnection = New SqlCeConnection("Data Source=C:\Users\Andy\Documents\uniapp5.sdf")
myConnection.Open()
Console.WriteLine("Connection Status: {0}", myConnection.State.ToString())
'run simple select query
Dim DataReader As SqlCeDataReader = Nothing
Query = New SqlCeCommand("Select * from Students JOIN Students_StudentRecord ON Students.StudentId = Students_StudentRecord.StudentId", myConnection)
DataReader = Query.ExecuteReader()
While DataReader.Read()
Console.WriteLine(DataReader("StudentId").ToString())
Console.WriteLine(DataReader("FirstName").ToString())
Console.WriteLine(DataReader("LastName").ToString())
Console.WriteLine(DataReader("ClassificationAwarded").ToString())
Console.WriteLine()
End While
Duration = DateTime.Now.Subtract(StartTime)
Console.WriteLine(String.Format("Query took {0} Seconds", Duration.TotalSeconds.ToString()))
Console.ReadLine()
'close connection
myConnection.Close()
Console.WriteLine("Connection Status: {0}", myConnection.State.ToString())
Console.ReadKey()
End Sub
End Module
Any help is greatly appreciated!
Thanks Andy
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
|