private void Form1_Load(object sender, EventArgs e)
{
BindDataBase(combDataBaseNew, , "");
BindDataBase(combDataBaseOld, , ""); }
//获取新数据库 0 是数据库 1是 表
private void BindDataBase(ComboBox combDataBase, int style, string database)
{
switch (style)
{
case :
{
string strSql = "select name from sysdatabases order by name";
combDataBase.DataSource = this.GetDataBases(strSql).Tables[];
combDataBase.DisplayMember = "name";
combDataBase.ValueMember = "name";
break;
}
case :
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("use {0}", database);
sb.AppendFormat(" SELECT Name from sysobjects Where Type='U' ORDER BY Name");
combDataBase.DataSource = this.GetDataBases(sb.ToString()).Tables[];
combDataBase.ValueMember = "name";
combDataBase.DisplayMember = "name";
break;
}
}
}
//获取数据库连接
private SqlConnection GetConnections()
{
SqlConnectionStringBuilder sqlsb = new SqlConnectionStringBuilder();
sqlsb.DataSource = "localhost";
sqlsb.IntegratedSecurity = true;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = sqlsb.ConnectionString;
return conn;
}
//根据查询语句,获取对应的数据集
private DataSet GetDataBases(string strSql)
{
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
using (SqlConnection conn = this.GetConnections())
{
conn.Open();
cmd.CommandText = strSql;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
sda.SelectCommand = cmd;
sda.Fill(ds, "databases");
conn.Close() ; }
return ds;
}
private int GetDoIt(string strSql)
{
SqlCommand cmd = new SqlCommand();
object b = null;
using (SqlConnection conn = this.GetConnections())
{
conn.Open();
cmd.CommandText = strSql;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
b= cmd.ExecuteNonQuery();
conn.Close();
}
return Convert.ToInt32(b);
}
private void btn_biaoOld_Click(object sender, EventArgs e)
{
BindDataBase(comOldtable, , combDataBaseOld.SelectedValue.ToString()); } private void btn_biaoNew_Click(object sender, EventArgs e)
{
BindDataBase(comNewtable, , combDataBaseNew.SelectedValue.ToString());
}
//绑定grid控件
public void GetTableZiDuan()
{
string strSql = string.Format("use {0} Select Name FROM SysColumns Where id=Object_Id('{1}')", combDataBaseOld.SelectedValue, comOldtable.SelectedValue);
this.dataGridView1.DataSource = GetDataBases(strSql).Tables[]; }
//绑定combobox控件
public void GetNewTableZiDuan()
{
string strSql = string.Format("use {0} Select Name FROM SysColumns Where id=Object_Id('{1}')", combDataBaseNew.SelectedValue, comNewtable.SelectedValue);
this.NewZiDuan.DataSource = GetDataBases(strSql).Tables[];
this.NewZiDuan.ValueMember = "name";
this.NewZiDuan.DisplayMember = "name";
}
private void btn_OldZiDuan_Click(object sender, EventArgs e)
{
GetTableZiDuan();
} private void btn_NewZiDuan_Click(object sender, EventArgs e)
{
GetNewTableZiDuan();
}
private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (this.dataGridView1.Rows.Count != )
{
for (int i = ; i < this.dataGridView1.Rows.Count; )
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += ;
}
}
} private void btn_StartZhuanLu_Click(object sender, EventArgs e)
{
List<string> oldList = new List<string>();
List<string> newList = new List<string>();
for (int i = ; i < this.dataGridView1.Rows.Count; i++)
{
if ((bool)(((DataGridViewCheckBoxCell)this.dataGridView1.Rows[i].Cells["isTrue"]).EditedFormattedValue) == true)
{
oldList.Add(dataGridView1.Rows[i].Cells["OldZiDuan"].Value.ToString());
newList.Add(((DataGridViewComboBoxCell)dataGridView1.Rows[i].Cells["NewZiDuan"]).Value.ToString());
}
}
OldToNew(oldList,newList,"");
}
private void OldToNew(List<string> oldList, List<string> newList, string where)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("use {0}",combDataBaseOld.SelectedValue);
sb.AppendFormat(" select ");
for (int i = ; i < oldList.Count; i++)
{
sb.AppendFormat(oldList[i] + ",");
}
sb.Remove(sb.ToString().LastIndexOf(','), );
sb.AppendFormat(" from {0}", comOldtable.SelectedValue);
if (!string.IsNullOrEmpty(where))
{
sb.AppendFormat(" where {0}", where);
}
MessageBox.Show(sb.ToString());
DataTable dt= GetDataBases(sb.ToString()).Tables[];
if (dt.Rows.Count > )
{
int sum = ;
for (int i = ; i < dt.Rows.Count; i++)
{
sum+=InsertNewDataBase(dt,i,newList,oldList);
}
if (sum == dt.Rows.Count)
{
MessageBox.Show("数据转录成功");
}
else
{
if (sum != )
{
MessageBox.Show("理论转录信息条数:" + dt.Rows.Count + ";实践转录信息条数:" + sum + ";实际转录条数与理论条数不符");
} }
}
else
{
MessageBox.Show("要转录的旧数据库,没有数据信息");
}
}
private int InsertNewDataBase(DataTable dt,int a,List<string> newList,List<string> oldList)
{
int sum = ;
try
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("use {0}", combDataBaseNew.SelectedValue);
sb.AppendFormat(" insert into {0} (", comNewtable.SelectedValue);
for (int i = ; i < newList.Count; i++)
{
sb.AppendFormat(newList[i] + ",");
}
sb.Remove(sb.ToString().LastIndexOf(','), );
sb.AppendFormat(")values(");
for (int i = ; i < oldList.Count; i++)
{
sb.AppendFormat("'" + dt.Rows[a][oldList[i]] + "'" + ",");
}
sb.Remove(sb.ToString().LastIndexOf(','), );
sb.AppendFormat(")");
MessageBox.Show(sb.ToString());
sum = GetDoIt(sb.ToString());
return sum;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return sum;
} }
}

sql数据库之间数据的转录的更多相关文章

  1. 不同版本的SQL Server之间数据导出导入的方法及性能比较

    原文:不同版本的SQL Server之间数据导出导入的方法及性能比较 工作中有段时间常常涉及到不同版本的数据库间导出导入数据的问题,索性整理一下,并简单比较下性能,有所遗漏的方法也欢迎讨论.补充. 0 ...

  2. 不同SQL数据库之间表数据的实时同步-发布与订阅

    https://blog.csdn.net/rand_muse/article/details/81326879 上述文章中,如果是实时同步,选择  事务发布即可 在快照代理 那里,不需要勾选  运行 ...

  3. oracle sql 数据库之间导入数据

    1.导入别的表 insert into EMPI_IDENTIFY select id,empiid, name||':' ||idcardno,'accidcardno','' from empi_ ...

  4. JSP Servlet SQL 三者之间数据传递

    前言: 最近一直在做WEB开发,现总结一下这一段时间的体会和感触. 切记,web开发重点在于前台数据交互,页面美化而不要太沉溺于底层数据. 浏览器时代来到,向我们召唤出更炫.更简洁.更方便.更大气的网 ...

  5. Oracle数据库之间数据同步

    这段时间负责某个项目开发的数据库管理工作,这个项目中开发库与测试数据库分离,其中某些系统表数据与基础资料数据经常需要进行同步,为方便完成指定数据表的同步操作,可以采用dblink与merge结合的方法 ...

  6. 【NIFI】 实现数据库到数据库之间数据同步

    本里需要基础知识:[NIFI] Apache NiFI 安装及简单的使用 数据同步 界面如下: 具体流程: 1.使用ExecuteSQL连接mysql数据库,通过写sql查询所需要的数据 2.nifi ...

  7. 【笔记】.NET开发环境下使用PostgreSQL+Oracle_fdw 实现两个数据库之间数据交互操作(二)

    一 新的可视化工具 因为前文所提到的,看不到外部服务器和外部表的问题,我更换了可视化工具. 好用的新工具PostgreSQL Maestro! 当然如此好用的工具不是免费的,如果想免费使用还请自己去找 ...

  8. sql 数据库 庞大数据量 需要分表

    17:04:05问下 在什么情况下 审核分区啊 ~..大熊..o○ 17:06:53这个要看应用~..大熊..o○ 17:07:37比如数据量很大,查询多是按照时间段查询,就可以用时间段来做分区~.. ...

  9. SQL不同服务器数据库之间的数据操作整理(完整版)

    ---------------------------------------------------------------------------------- -- Author : htl25 ...

随机推荐

  1. css伪元素

    CSS 伪元素用于向某些选择器设置特殊效果. 1.:first-line 伪元素  "first-line" 伪元素用于向文本的首行设置特殊样式.注意:"first-li ...

  2. [HTML5 Canvas学习]使用颜色和透明度

    在canvas中使用颜色和透明度,通过context的strokeStyle和fillStyle属性设置,strokeStyle和fillStyle的值可以是任意有效的css颜色字串.可以用RGB.R ...

  3. Yii框架AR对象数据转化为数组

    demo函数作用:将AR对象数据转化为数组 局限:仅用于findAll的多维数组,find一维数组可以先转化为多维数组的一个元素在使用 function actionIndex() { $data = ...

  4. jdbc 连接mysql Communications link failure的解决办法

    使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误: Communications link failure,The last packet successfully r ...

  5. linux命令——Grep 命令 用法大全

    1. 参数: -I :忽略大小写 -c :打印匹配的行数 -l :从多个文件中查找包含匹配项 -v :查找不包含匹配项的行 -n:打印包含匹配项的行和行标 2.RE(正则表达式) \ 忽略正则表达式中 ...

  6. 总结:ARM逻辑和高级C(朱老师物联网学习)

    开始学习朱老师物联网的视频是国庆节的那几天开始的,刚刚开始的时候是想自己在网上找一些嵌入式方面的视频资料,也找了很多的资料臂如“国嵌视频”“达内的视频”,之后也化了十几块钱在淘宝上面买了几十个G的视频 ...

  7. POJ 3356(最短编辑距离问题)

    POJ - 3356 AGTC Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Desc ...

  8. libcurl 下载上传

    近来一个新的项目需要使用到http. 本来用socket来写一个的,后来发现功能实在太简单,有点捉襟见肘. 于是改用libcur来做. 首先下载libcur的源码,然后配置: ./configure ...

  9. h.264 mvp求解过程

    h.264标准中由于分为宏块分割块(8x8),子宏块分割块(4x4),所以各种各样的求解过程比较繁琐 下面整理出标准中mvp的求解过程 8.4.1.3 已知条件有当前块的属性:位置.块类型需要得到当前 ...

  10. NEW关键字的三种用法

    最近面试中有一道题是写new关键字的几种用法,想了下写下我知道的两种用法 第一种 创建对象.调用构造函数,这就不用讲了 ClassA  A=new ClassA(); 第二种 是作为修饰符,显示隐藏继 ...