Created
October 30, 2013 16:37
-
-
Save kiyokura/7235828 to your computer and use it in GitHub Desktop.
Glimpse.Adoを利用する場合の例
This file contains hidden or 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
// 接続文字列。環境に合わせてください。 | |
var connectionString = "Data Source=\"c:\\users\\kiyokura\\documents\\visual studio 2012\\Projects\\WebApplication12\\WebApplication12\\App_Data\\Database1.sdf\"" ; | |
// SQL Server CEで試した例。SQL Serverの場合はSystem.Data.SqlClient.SqlConnectionを使ってください | |
using ( var cnOrg = new System.Data.SqlServerCe.SqlCeConnection (connectionString)) | |
{ | |
using ( var cn = new Glimpse.Ado.AlternateType.GlimpseDbConnection (cnOrg)) | |
{ | |
cn.Open(); | |
var cmd = cn.CreateCommand(); | |
cmd.CommandText = "SELECT * FROM users WHERE Age > @Age"; | |
var param = cmd.CreateParameter(); | |
param.ParameterName = "Age" ; | |
param.DbType = System.Data.DbType.Int32; | |
param.Value = 20; | |
cmd.Parameters.Add(param); | |
using ( var dr = cmd.ExecuteReader()) | |
{ | |
// ここでカラムを読む処理を行う | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment