本文整理汇总了C#中System.Data.IDbConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.IDbConnection.Open方法的具体用法?C# System.Data.IDbConnection.Open怎么用?C# System.Data.IDbConnection.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.IDbConnection
的用法示例。
在下文中一共展示了System.Data.IDbConnection.Open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConnection
public bool TestConnection(string query)
{
try
{
IConn = this.GetConnection();
IConn.Open();
bool result = false;
System.Data.IDbCommand cmd = IConn.CreateCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = query;
System.Data.IDataReader _reader = cmd.ExecuteReader();
result = (_reader.FieldCount > 0);
_reader.Close();
IConn.Close();
return result;
}
catch (Exception ex) {
Logger.Error(ex.Message);
}
return false;
}
示例2: Main
/*
* 使用微软提供的操作Offfice的库DocumentFormat.OpenXml
* ClosedXML在此基础上进行了封装,简化操作。
*
* */
static void Main(string[] args)
{
HZ_Conn = new SqlConnection(HZ_ConnectionString);
HZ_Conn.Open();
DC_Conn = new SqlConnection(DC_ConnectionString);
DC_Conn.Open();
var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Sheet1");
var url = "http://webapp.hc.ihaozhuo.com/SMSPromotion.html#/{0}/{1}/{2}";
//http://webapp.hc.ihaozhuo.com/SMSPromotion.html#/{task}/{mobile}/{org}
var table = "bjbr008";
var deptCode = "bjbr008";
//黎波,刘述正,刘倩倩,
//var mobiles = new string[] { "15900860546", "17783055953","15601815186"};
var mobiles = HZ_Conn.Query<string>("select distinct telephone from " + table);//distinct
var shortLinkProxy = SortLinkServerProxy.ShareInstance();
var time = DateTime.Now;
var sms = (from c in mobiles
where !string.IsNullOrEmpty(c) && Regex.Match(c, "1[2|3|5|7|8|][0-9]{9}").Success
select new
{
mobile = c,
sms = shortLinkProxy.getSortLink(string.Format(url, 1, c, deptCode)) + " "
}).ToList();
Trace.WriteLine(string.Format("cost:{0}", DateTime.Now.Subtract(time).TotalSeconds));
var rowStart = 2;
var columnStart = 1;
foreach (var item in sms)
{
worksheet.Cell(rowStart, columnStart).Value = item.mobile;
worksheet.Cell(rowStart, columnStart + 1).Value = "【新乡第一人民医院】温馨提示,您的体检报告已完成,查看您的健康状况及阳性指标,永久保存报告详情请点击";
worksheet.Cell(rowStart, columnStart + 2).Value = item.sms + " 退订回N";
worksheet.Cell(rowStart, columnStart + 3).Value = item.sms;
rowStart++;
}
workbook.SaveAs("HelloWorld.xlsx");
}