zoukankan      html  css  js  c++  java
  • 连接数据库

    private string connectionString;
            private void SaveCustomerInfo() {
                var entityConnStr = ConfigurationManager.ConnectionStrings["DcsEntities"].ConnectionString;
                if(!string.IsNullOrEmpty(entityConnStr)) {
                    var entityConnection = new EntityConnectionStringBuilder(entityConnStr);
                    this.connectionString = entityConnection.ProviderConnectionString;
                }
                var db = DbHelper.GetDbHelp(this.connectionString);
                var sqlInsert = db.GetInsertSql("reportquerylog ", "Id", new[] {
                                    "UserId","EnterpriseId","CreateTime","PageName"
                                });
     
                using(var conn = db.CreateDbConnection()) {
                    conn.Open();
                    var ts = conn.BeginTransaction();
                    try {
                        var cmd = db.CreateDbCommand(sqlInsert, conn, null);
                       // cmd.Parameters.Add(db.CreateDbParameter("Id", Guid.NewGuid()));
                        cmd.Parameters.Add(db.CreateDbParameter("UserId", Utils.GetCurrentUserInfo().LoginId));
                        cmd.Parameters.Add(db.CreateDbParameter("EnterpriseId", Utils.GetCurrentUserInfo().EnterpriseId));
                        cmd.Parameters.Add(db.CreateDbParameter("CreateTime", DateTime.Now));
                        cmd.Parameters.Add(db.CreateDbParameter("PageName", "23"));
                        cmd.ExecuteNonQuery();
                        ts.Commit();
     
                    } catch(Exception) {
                        ts.Rollback();
                    } finally {
                        conn.Close();
                    }
                }
            }
  • 相关阅读:
    Java数据库小项目02--管家婆项目
    Java数据库小项目01--实现用户登录注册
    Java数据库小项目00---基础知识
    MySQL基础练习02---牛客网
    ICMP
    语法糖
    双绞线
    telnet 时代的 bbs
    ARPA
    IEEE802是一个局域网标准系列
  • 原文地址:https://www.cnblogs.com/naliang/p/5573296.html
Copyright © 2011-2022 走看看