Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Apr 16th, 2010 | Syntax: VB.NET | Size: 1.58 KB | Hits: 501 | Expires: Never
Copy text to clipboard
  1. Imports System.Data.SqlClient
  2.  
  3. Module Module1
  4.  
  5.     Sub Main(ByVal sArgs() As String)
  6.  
  7.         Dim ConnString As String
  8.  
  9.         'Connstring = Server Name, Database Name, Windows Authentication
  10.         ConnString = "Data Source=MATHEW-PC\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True"
  11.  
  12.         'Write to SQL
  13.  
  14.         Dim SQLConn As New SqlConnection() 'The SQL Connection
  15.         Dim SQLCmd As New SqlCommand() 'The SQL Command
  16.  
  17.         SQLConn.ConnectionString = ConnString 'Set the Connection String
  18.         SQLConn.Open() 'Open the connection
  19.  
  20.         Try
  21.             SQLCmd = New SqlCommand("sps_rssfeeds_insert", SQLConn)
  22.             SQLCmd.CommandType = CommandType.StoredProcedure
  23.  
  24.             Dim sampParm As SqlParameter = SQLCmd.Parameters.Add("@p_rssid", SqlDbType.Int)
  25.             sampParm.Direction = ParameterDirection.Output
  26.  
  27.             sampParm = SQLCmd.Parameters.Add("@p_url", SqlDbType.VarChar, 1024)
  28.             sampParm.Value = "Sample Url"
  29.  
  30.             sampParm = SQLCmd.Parameters.Add("@p_name", SqlDbType.VarChar, 50)
  31.             sampParm.Value = "Sample Name"
  32.             SQLCmd.ExecuteNonQuery()
  33.  
  34.             Dim iRSSID As Integer = DirectCast(SQLCmd.Parameters("@p_rssid").Value, Integer)
  35.  
  36.             Console.WriteLine("Rows inserted: {0}", iRSSID)
  37.  
  38.         Catch ex As Exception
  39.             Console.WriteLine(ex.Message)
  40.             Throw
  41.         Finally
  42.             SQLConn.Close()
  43.         End Try
  44.  
  45.         SQLConn.Close() 'Close the connection  
  46.         SQLConn.Dispose()
  47.  
  48.         Console.ReadLine()
  49.     End Sub
  50. End Module