SQL

From $1

Table of contents
No headers

Here's a basic example of inserting a record into a SQLServer database

require 'mscorlib'
require 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

include System::Data::SqlClient

begin
  connection = SqlConnection.new('Server=localhost;Database=TestDatabase;Trusted_Connection=true')
  connection.open

  command = SqlCommand.new(<<-EOS
    insert into customers(first_name,last_name)
    values(@first_name,@last_name)
  EOS, connection)

  command.parameters.add_with_value "@first_name", "Jimmy"
  command.parameters.add_with_value "@last_name", "Schementi"

  command.execute_non_query
ensure
  connection.close if connection
end
Tags:
 
Images (0)
 
Comments (0)
You must login to post a comment.

 
SourceForge.net