Skip to content

Instantly share code, notes, and snippets.

@iOS0x00
Created December 26, 2013 01:20
Show Gist options
  • Save iOS0x00/8128552 to your computer and use it in GitHub Desktop.
Save iOS0x00/8128552 to your computer and use it in GitHub Desktop.
 连接mssql数据库查询的sample
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