[Ironruby-core] Accessing Database Using IronRuby

Jimmy Schementi Jimmy.Schementi at microsoft.com
Wed Jun 17 17:03:59 EDT 2009


Thanks! I've added this to the IronRuby .NET documentation just as a placeholder:

http://ironruby.net/Documentation/.NET/SQL

~js

> -----Original Message-----
> From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-
> bounces at rubyforge.org] On Behalf Of Mohammad Azam
> Sent: Wednesday, June 17, 2009 1:33 PM
> To: ironruby-core at rubyforge.org
> Subject: Re: [Ironruby-core] Accessing Database Using IronRuby
>
> Just wanted to share basic code to insert first_name and last_name into the
> database.
>
>
> require 'mscorlib'
> require 'System.Data, Version=2.0.0.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089'
>
> SqlConnection = System::Data::SqlClient::SqlConnection
> SqlCommand = System::Data::SqlClient::SqlCommand
>
> class CustomerRepository
>
>   def save(customer)
>
>    connection =
> SqlConnection.new('Server=localhost;Database=TestDatabase;Trusted_Con
> nection=true')
>    connection.Open()
>    command = SqlCommand.new("insert into
> customers(first_name,last_name)
> values(@first_name, at last_name)",connection)
>
> command.Parameters.AddWithValue("@first_name",customer.first_name)
>    command.Parameters.AddWithValue("@last_name",customer.last_name)
>
>    command.ExecuteNonQuery()
>    connection.Close()
>
>   end
>
> end
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core



More information about the Ironruby-core mailing list