Thanks, the change has been made.
From: [email protected]
[mailto:[email protected]] On Behalf Of Brannon Jones
Sent: Wednesday, June 17, 2009 4:25 PM
To: [email protected]
Subject: Re: [Ironruby-core] Accessing Database Using IronRuby
That code should use 'ensure', to make sure the connection is closed at the end
of the block:
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 unless connection.nil?
end
On Wed, Jun 17, 2009 at 14:03, Jimmy Schementi
<[email protected]<mailto:[email protected]>> wrote:
Thanks! I've added this to the IronRuby .NET documentation just as a
placeholder:
http://ironruby.net/Documentation/.NET/SQL
~js
> -----Original Message-----
> From:
> [email protected]<mailto:[email protected]>
> [mailto:ironruby-core-<mailto:ironruby-core->
> [email protected]<mailto:[email protected]>] On Behalf Of Mohammad
> Azam
> Sent: Wednesday, June 17, 2009 1:33 PM
> To: [email protected]<mailto:[email protected]>
> 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,@last_name)",connection)
>
> command.Parameters.AddWithValue("@first_name",customer.first_name)<mailto:%22,connection)%0b%3e%0b%3e%20command.Parameters.AddWithValue(%...@first_name%22,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
> [email protected]<mailto:[email protected]>
> http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
[email protected]<mailto:[email protected]>
http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core