Created
December 26, 2013 01:20
-
-
Save iOS0x00/8128552 to your computer and use it in GitHub Desktop.
连接mssql数据库查询的sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import clr | |
clr.AddReference('System.Data') | |
from System.Data.SqlClient import SqlConnection, SqlParameter | |
conn_string = 'data source=<machine>; initial catalog=<database>; trusted_connection=True' | |
connection = SqlConnection(conn_string) | |
connection.Open() | |
command = connection.CreateCommand() | |
command.CommandText = 'select id, name from people where group_id = @group_id' | |
command.Parameters.Add(SqlParameter('group_id', 23)) | |
reader = command.ExecuteReader() | |
while reader.Read(): | |
print reader['id'], reader['name'] | |
connection.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment