예제 #1
0
 public void Insert <T>(string connection, T obj) where T : class
 {
     using (var c = new MySqlData.MySqlClient.MySqlConnection(connection))
     {
         c.Open();
         c.Insert(obj);
         c.Close();
     }
 }
예제 #2
0
 public void Insert <T>(T obj) where T : class
 {
     using (var connection = new MySqlData.MySqlClient.MySqlConnection(_connection))
     {
         connection.Open();
         connection.Insert(obj);
         connection.Close();
     }
 }
예제 #3
0
        public async Task InsertAsync <T>(T obj) where T : class
        {
            await Task.Run(() => {
                using (var connection = new MySqlData.MySqlClient.MySqlConnection(_connection))
                {
                    connection.Open();

                    connection.Insert(obj);

                    connection.Close();
                }
            });
        }
예제 #4
0
        public async Task InsertAsync <T>(string connection, T obj) where T : class
        {
            await Task.Run(() => {
                using (var c = new MySqlData.MySqlClient.MySqlConnection(connection))
                {
                    c.Open();

                    c.Insert(obj);

                    c.Close();
                }
            });
        }
예제 #5
0
        public long Insert <T>(T entityToInsert) where T : class
        {
            long lResult = 0;

            try
            {
                //using (var cn = new System.Data.SqlClient.SqlConnection(ConnStr))
                //{
                //    lResult = cn.Insert<T>(entityToInsert);
                //}

                if (_ProviderName == "System.Data.SqlClient")
                {
                    using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(ConnStr))
                    {
                        lResult = cn.Insert <T>(entityToInsert);
                    }
                }
                else if (_ProviderName == "MySql.Data.MySqlClient")
                {
                    using (MySql.Data.MySqlClient.MySqlConnection cn = new MySql.Data.MySqlClient.MySqlConnection(ConnStr))
                    {
                        lResult = cn.Insert <T>(entityToInsert);
                    }
                }
                else
                {
                    using (System.Data.SqlClient.SqlConnection cn = SqlClient)
                    {
                        lResult = cn.Insert <T>(entityToInsert);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(lResult);
        }