Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ruby Á¬½Ó²Ù×÷ sql2005


The following is improved version of the code created by David Mullet, from
http://rubyonwindows.blogspot.com/2007/03/ruby-ado-and-sqlserver.html
require 'win32ole'
class SqlServer
# This class manages database connection and queries
attr_accessor :connection, :data, :fields
attr_writer :username, :password
def initialize(host, username = 'sa', password='')
@connection = nil
@data = nil
@host = host
@username = username
@password = password
end
def open(database)
# Open ADO connection to the SQL Server database
connection_string = "Provider=SQLOLEDB.1;"
connection_string << "Persist Security Info=False;"
connection_string << "User ID=#{@username};"
connection_string << "password=#{@password};"
connection_string << "Initial Catalog=#{database};"
connection_string << "Data Source=#{@host};"
connection_string << "Network Library=dbmssocn"
@connection = WIN32OLE.new('ADODB.Connection')
@connection.Open(connection_string)
end
def query(sql)
# Create an instance of an ADO Recordset
recordset = WIN32OLE.new('ADODB.Recordset')
# Open the recordset, using an SQL statement and the
# existing ADO connection
recordset.Open(sql, @connection)
# Create and populate an array of field names
@fields = []
recordset.Fields.each do |field|
@fields << field.Name
end
begin
# Move to the first record/row, if any exist
recordset.MoveFirst
# Grab all records
@data = recordset.GetRows
rescue
@data = []
end
recordset.Close
# An ADO Recordset's GetRows method returns an array
# of columns, so we'll use the transpose method to
# convert it to an array of rows
@data = @dat


Ïà¹ØÎĵµ£º

ÈçºÎ½« Access Êý¾Ý¿âת»»µ½ SQL Server

http://support.microsoft.com/default.aspx/kb/237980/zh-cn
½« Access Êý¾Ý¿âת»»Îª SQL Server µÄ×î¼ò±ã·½·¨ÊÇʹÓÃÉýǨÏòµ¼¡£ÉýǨÏòµ¼£º
±£ÁôÊý¾Ý¿â½á¹¹£¬°üÀ¨Êý¾Ý¡¢Ë÷ÒýºÍĬÈÏÉèÖá£
×Ô¶¯½« Access ÓÐЧÐÔ¹æÔòºÍĬÈÏÉèÖÃת»»ÎªÊʵ±µÄ SQL Server µÈЧÄÚÈÝ¡£
ÔÚÉýǨºó±£³Ö±í¹ØϵºÍ²ÎÕÕÍêÕûÐÔ¡£
ÒªÔÚ Access 2000 ......

SQL Server 2000 Êý¾Ý¿âͬ²½

ÎÄÕÂÀ´Ô´£ºhttp://blog.sina.com.cn/s/blog_537ca30d0100bvja.html
ΪʲôҪͬ²½SQL Server 2000 Êý¾Ý¿â£¬Ëü¶¼ÓÃÔÚʲô³¡ºÏ
Êý¾Ýʵʱ±¸·Ýͬ²½£¬Êý¾Ý¿â·þÎñÆ÷³öÎÊÌâʱÎÒÃÇÒ²ÓÐÆäÕý³£¹¤×÷ʱµÄ±¸·Ý
Êý¾Ýʵʱ±¸·Ýͬ²½£¬Ò»Ì¨·þÎñÆ÷¸ºÔز»Æðʱ£¬¿ÉÒÔÓÃÀ´×ö¸ºÔؾùºâ
Êý¾Ýʵʱ±¸·Ýͬ²½£¬Êý¾Ý¿â·þÎñÆ÷¿ÉÒÔÎÞ¼ä¶Ï£¬ÎÞËðʧǨÒÆ ......

Óû§saµÇ¼ʧ°Ü,¸ÃÓû§Óë¿ÉÐÅsql serverÁ¬½ÓÎÞ¹ØÁª

SQLSERVER 2005²ÉÓÃ'SQLSERVERÉí·ÝÑéÖ¤'È¥µÇ¼, ³ö´íµÄÔ­ÒòÊÇ:'Óû§ 'sa' µÇ¼ʧ°Ü¡£¸ÃÓû§Óë¿ÉÐÅ SQL Server Á¬½ÓÎÞ¹ØÁª'.½ñÌìÉÏÍøÉϲéÁË°ëÌì²Å¸ã¶¨µÄ¡£
¾ßÌåµÄ·½·¨ÊÇ£º ¡¡¡¡
1£º´ò¿ªSQL Server Manager¹ÜÀíÆ÷£¡ÔÚ×óÃæÕÒµ½ ‘°²È«ÐÔ’ µ¥»÷ÓÒ¼ü Ñ¡Ôñ‘н¨”£¬“µÇ¼” µ¯³öÒ»¸ö¶Ô»°¿ò£¬Ô ......

ÔÚXPÉÏ°²×°SQL 2000 Server(ժת)

½ñÌì´ÓÍøÂçÉÏÕÒµ½ÁËÔÚXPÉÏ°²×°SQL 2000 ServerµÄ·½·¨£¬´ËÇ°ÎÒÒ»Ö±ÈÏΪÕâÊÇÐв»Í¨µÄ£¬ºóÃægoogleÒ»²é£¬»¹ÕæÊÇ¿ÉÒÔ£¬ÓкܶàÍøÕ¾¶¼ËµÕâ¸ö·½·¨¿ÉÐУ¬ÎÒ¾ÍÈÃlpÊÔÊÔ¿´£¬½á¹ûÕæÐУ¬×ªÔØһϰɣº ÔÚWindows XPÉÏ°²×°SQL Server 2000µÄÖ÷ÒªÁ÷³ÌΪ£º
Ò»¡¢ÔÚSQL·þÎñÆ÷µÄ°²×°ÅÌÖÐÕÒµ½MSDEÕâ¸öĿ¼£¬²¢ÇÒµã»÷setup.exe°²×°Ëü£¬¹ý³Ì ......

Sql·ÖÒ³´úÂë

select * from books
where 1=1
and categoryid=29
and title like('%ASP.NET%')
and unitprice>10
order by id
Select top 20 * from books order by id
--m:ÿҳÏÔʾÐÐÊý n£ºµ±Ç°Ò³Êý
select Top m * from books
where id not in
(Select top m(n-1) id from books order by id)
order by id
select * fro ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ