本文介绍了如何将表和值从一个数据库移动到另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 亲爱的朋友们, 我需要使用Windows服务将表和值从一个数据库移动到另一个数据库..我尝试了以下链接:我收到错误无效对象名称.. Sqlite:将数据从所有db1表复制到db2表 [ ^ ] 我尝试过: public void Move() {< pre> ; StringBuilder strSql = new StringBuilder(); 使用(con) { con.Open(); 使用(cmd1 = new SqlCommand(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG ='AWACS'和TABLE_NAME ='DRL_MenuMaster_hdr',con)) { using( SqlDataReader rdr = cmd1.ExecuteReader()) { while(rdr.Read())//读取行 { strSql.Append(INSERT INTO MOVEDB.dbo。 ); strSql.Append(rdr [TABLE_NAME]。ToString()); strSql.Append((); strSql.Append(rdr [COLUMN_NAME]。ToString()); strSql.Append()); strSql.Append(SELECT); strSql.Append(rdr [COLUMN_NAME]。ToString()); strSql.Append(FROM AWACS.dbo。); strSql.Append(rdr [TABLE_NAME]。ToString()); strSql.Append(;); var tableName = rdr [TABLE_NAME]。ToString(); var Columns = rdr [COLUMN_NAME]。ToString(); } } } } 使用(con1) { con1.Open() ; using(SqlCommand cmd2 = new SqlCommand(strSql.ToString(),con1)) { //cmd1.CommandText = strSql.ToString(); int i = cmd2.ExecuteNonQuery(); if(i> 0) { MessageBox.Show(数据转储成功...... !!!); } } } } 解决方案 SQLite不使用SqlCommand对象 - 它使用SQLiteCommand,SQLiteConnection等构造。如果要访问SQLite数据库,则必须使用SQL Server数据库。 有许多方法可以在SQL Server数据库之间复制表:在SQL服务器数据库之间复制一个表 - Google搜索 [ ^ ] - 每个都有自己的优点和缺点,具体取决于您的情况。看看,按照几个链接,看看你能找到哪些符合你想要达到的目的。 你应该在web.Config或App.Config中维护两个连接字符串 1)从database1获取所有数据并将其填入DataTable 2)使用 SQL批量复制将所有数据转储到database2 / b> 有关批量复制的更多信息,您应该查看这些链接 使用c#.net 在SQL服务器中批量复制[ ^ ] SQL Bulk使用C#.Net 复制[ ^ ] Dear friends,I need to move tables and values from one database to another using windows service.. I tried the following link: I got an error invalid object name..Sqlite: copy data from all db1 tables to db2 tables[^]What I have tried:public void Move() { <pre>StringBuilder strSql = new StringBuilder(); using (con) { con.Open(); using (cmd1 = new SqlCommand("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG ='AWACS' and TABLE_NAME ='DRL_MenuMaster_hdr'", con)) { using (SqlDataReader rdr = cmd1.ExecuteReader()) { while (rdr.Read()) // Reading Rows { strSql.Append("INSERT INTO MOVEDB.dbo."); strSql.Append(rdr["TABLE_NAME"].ToString()); strSql.Append(" ("); strSql.Append(rdr["COLUMN_NAME"].ToString()); strSql.Append(") "); strSql.Append("SELECT "); strSql.Append(rdr["COLUMN_NAME"].ToString()); strSql.Append(" FROM AWACS.dbo."); strSql.Append(rdr["TABLE_NAME"].ToString()); strSql.Append(";"); var tableName = rdr["TABLE_NAME"].ToString(); var Columns = rdr["COLUMN_NAME"].ToString(); } } } } using (con1) { con1.Open(); using (SqlCommand cmd2 = new SqlCommand(strSql.ToString(), con1)) { //cmd1.CommandText = strSql.ToString(); int i = cmd2.ExecuteNonQuery(); if (i > 0) { MessageBox.Show("Data dumped successfully ...!!!"); } } } } 解决方案 SQLite does not use SqlCommand objects - it uses SQLiteCommand, SQLiteConnection, and such like constructs. If you want to access SQLite databases, you have to use those instead SQL server classes.There are many ways to copy a table between SQL server databases: copy a table between SQL server databases - Google Search[^] - each with thier own advantages and disadvantages depending on your situation. Have a look, follow a few links, and see what you can find that fits what you are trying to achieve.You should maintain two connection string in web.Config or App.Config1) Get all data from database1 and fill it into DataTable2) Dump all data to database2 using SQL Bulk Copyfor more info regarding bulk copy, you should check these linksBulk Copy in SQL server using c#.net[^]SQL Bulk Copy with C#.Net[^] 这篇关于如何将表和值从一个数据库移动到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-28 12:50