17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

}<br />

Console.ReadLine();<br />

// Change the command<br />

sqlMyCommand.CommandText = strCommand2;<br />

sqlMyCommand.ExecuteNonQuery();<br />

Console.WriteLine(“It’s gone”);<br />

Console.WriteLine();<br />

Console.WriteLine(“Press any key to continue...”);<br />

Console.ReadKey();<br />

}<br />

finally<br />

{<br />

// Clean up<br />

if (cnMyConn != null)<br />

{<br />

cnMyConn.Close();<br />

}<br />

}<br />

Connecting in VB.NET<br />

VB.NET continues replacing the venerable Visual Basic. While I’m increasingly favoring C# for my own<br />

efforts, VB remains the code of choice for many.<br />

Returning a Data Set<br />

Imports System<br />

Imports System.Data<br />

Imports System.Data.SqlClient<br />

Module Program<br />

Sub Main()<br />

Appendix B: Very Simple Connectivity Examples<br />

‘Create some base strings so you can look at these<br />

‘separately from the commands they run in<br />

‘ Integrated Security - next 2 lines should be uncommented to use<br />

‘ Windows authentication<br />

Dim strConnect As String = _<br />

“Data Source=(local);Initial Catalog=master;Integrated Security=SSPI”<br />

‘ <strong>SQL</strong> Security - next 2 lines should be uncommented to use<br />

‘ <strong>SQL</strong> <strong>Server</strong> authentication<br />

‘Dim strConnect As String = _<br />

‘ “Data Source=(local);Initial Catalog=master;User Id=sa;Password=MyPass”<br />

Dim strCommand As String = _<br />

“SELECT Name, database_id as ID FROM sys.databases”<br />

653

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!