原文地址:http://blog.csdn.net/smartsmile2012/article/details/22167179sql
- private void button1_Click(object sender, EventArgs e)
- {
-
- DateTime starttime = DateTime.Now;
- using (SQLiteConnection con = new SQLiteConnection(connStr))
- {
- con.Open();
- DbTransaction trans = con.BeginTransaction();
- SQLiteCommand cmd = new SQLiteCommand(con);
- try
- {
- cmd.CommandText = "INSERT INTO MyTable(username,useraddr,userage) VALUES(@a,@b,@c)";
- for (int n = 0; n < 100000; n++)
- {
- cmd.Parameters.Add(new SQLiteParameter("@a", DbType.String));
- cmd.Parameters.Add(new SQLiteParameter("@b", DbType.String));
- cmd.Parameters.Add(new SQLiteParameter("@c", DbType.String));
- cmd.Parameters["@a"].Value = "張三" + n;
- cmd.Parameters["@b"].Value = "深圳" + n;
- cmd.Parameters["@c"].Value = 10 + n;
- cmd.ExecuteNonQuery();
- }
- trans.Commit();
- DateTime endtime = DateTime.Now;
- MessageBox.Show("插入成功,用時" + (endtime - starttime).TotalMilliseconds);
-
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
-
- try
- {
- using (MySqlConnection con = new MySqlConnection(MySqlStr))
- {
- con.Open();
- DbTransaction trans = con.BeginTransaction();
-
- #region 防重複先刪除
-
- for (int i = 0; i < count; i++)
- {
- DataRow dr = ds.Tables[0].Rows[i];
- string sqlDelete = "delete from packect where proimei=@d";
- MySqlCommand cmd1 = new MySqlCommand(sqlDelete, con);
- cmd1.Parameters.Add(new MySqlParameter("@d", MySqlDbType.String));
- cmd1.Parameters["@d"].Value = dr["proimei"];
- cmd1.ExecuteNonQuery();
- }
- #endregion
-
-
- #region 新增數據
-
- for (int i = 0; i < count; i++)
- {
- DataRow dr = ds.Tables[0].Rows[i];
- string sqlInsert = "insert into packect(proimei, prokg, proadddate) values(@a,@b,@c)";
- MySqlCommand cmd2 = new MySqlCommand(sqlInsert, con);
- cmd2.Parameters.Add(new MySqlParameter("@a", MySqlDbType.String));
- cmd2.Parameters.Add(new MySqlParameter("@b", MySqlDbType.Decimal));
- cmd2.Parameters.Add(new MySqlParameter("@c", MySqlDbType.DateTime));
- cmd2.Parameters["@a"].Value = dr["proimei"];
- cmd2.Parameters["@b"].Value = dr["prokg"];
- cmd2.Parameters["@c"].Value = dr["proadddate"];
- cmd2.ExecuteNonQuery();
- }
- #endregion
-
- trans.Commit();
- DateTime endtime = DateTime.Now;
- MessageBox.Show("上傳數據成功,用時" + (endtime - starttime).TotalMilliseconds + "毫秒!");
-
- SQLiteHelper.ExecuteNonQuery(connStr, "delete from table1", CommandType.Text);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void SqlBulkCopyInsert(DataTable table, string tableName)
- {
- SqlBulkCopy sbc = new SqlBulkCopy(MSCL.Until.GetApp("SqlConnStr"));
- sbc.DestinationTableName = tableName;
-
- for (int i = 0; i < table.Columns.Count; i++)
- {
- sbc.ColumnMappings.Add(table.Columns[i].ColumnName, table.Columns[i].ColumnName);
- }
- sbc.WriteToServer(table);
- }
-
-
-
-
-
-
-
- public void SqlBulkCopyInsert(DataTable table, string tableName, string[] columns)
- {
- SqlBulkCopy sbc = new SqlBulkCopy("接連字符串");
- sbc.DestinationTableName = tableName;
- foreach (string col in columns)
- {
- sbc.ColumnMappings.Add(col, col);
- }
- sbc.WriteToServer(table);
- }
-
-
-
-
-
-
-
-
- public int MultyInsert(DataSet ds)
- {
- int result = 0;
- IDbConnection con = new OracleConnection("鏈接字符串");
- con.Open();
- IDbCommand cmd = new OracleCommand();
- cmd.CommandText = "Insert into Member(UserName,Password) values(@name,@password)";
- IDbDataParameter namePar = cmd.CreateParameter();
- namePar.ParameterName = "@name";
- namePar.SourceColumn = "UserName";
- namePar.SourceVersion = DataRowVersion.Original;
- namePar.DbType = DbType.String;
- cmd.Parameters.Add(namePar);
-
- IDbDataParameter passPar = cmd.CreateParameter();
- passPar.ParameterName = "@pass";
- passPar.DbType = DbType.String;
- passPar.SourceColumn = "Password";
- passPar.SourceVersion = DataRowVersion.Original;
- cmd.Parameters.Add(passPar);
-
- IDbDataAdapter adpt = new OracleDataAdapter();
- adpt.InsertCommand = cmd;
- try
- {
- result = adpt.Update(ds);
- }
- catch (Exception)
- {
-
- throw;
- }
- finally
- {
- con.Close();
- }
- return result;
- }
-
-
-
-
-
-
-
-
- string connectStr = "User Id=scott;Password=tiger;Data Source=";
- OracleConnection conn = new OracleConnection(connectStr);
- OracleCommand command = new OracleCommand();
- command.Connection = conn;
-
-
- int recc = 10000000;
- command.ArrayBindCount = recc;
-
-
- command.CommandText = "insert into dept values(:deptno, :deptname, :loc)";
- conn.Open();
-
- int[] deptNo = new int[recc];
- string[] dname = new string[recc];
- string[] loc = new string[recc];
-
-
- OracleParameter deptNoParam = new OracleParameter("deptno", OracleType.Int32);
- deptNoParam.Direction = ParameterDirection.Input;
- deptNoParam.Value = deptNo;
- command.Parameters.Add(deptNoParam);
- OracleParameter deptNameParam = new OracleParameter("deptname", OracleType.VarChar);
- deptNameParam.Direction = ParameterDirection.Input;
- deptNameParam.Value = dname; command.Parameters.Add(deptNameParam);
- OracleParameter deptLocParam = new OracleParameter("loc", OracleType.VarChar);
- deptLocParam.Direction = ParameterDirection.Input;
- deptLocParam.Value = loc;
- command.Parameters.Add(deptLocParam);
-
- for (int i = 0; i < recc; i++)
- {
- deptNo[i] = i;
- dname[i] = i.ToString();
- loc[i] = i.ToString();
- }
-
- command.ExecuteNonQuery();