Coin163

首页 > [置顶] 黑马程序员 将Access数据库里的数据导入Sql server数据库里

[置顶] 黑马程序员 将Access数据库里的数据导入Sql server数据库里

相关标签: 程序员 server access sql

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

相关推荐:利用python操作access,sql server数据库 - 博客频道 - CSDN.NET

 来源:http://john2007.javaeye.com/blog/309023   本文主要介绍了python如何利用 ADO访问windows平台下的数据库,比如access,sql server. (译者注:作者原文用的IDE是pythonwin,但我的pytonwin重装了两遍了就是用不起来,就算写个helloworld运行也崩掉,妈

---------------------- Windows Phone 7手机开发.Net培训、期待与您交流! ----------------------     前几天在黑马论坛上遇到一个网友求手机IP地址的数据,我便回复,网上如果找不到的话可以加我QQ,今晚下班回来,打开QQ给他传过去~结 果让他想不到,用不了,因为我在网下下的是Access的数据库,而他用的是Sql Server数据库,然后我就引用了前几天所学的知识~些了一小段 程序,把Access数据库里的数据导入到Sql Server,虽然代码不够简洁,但还是顺利的完成啦~哈哈,希望网友给予改善
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;//导入Access数据库的命名空间
using System.Data.SqlClient; namespace 把Access书库导入Sql_server
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }         private void button1_Click(object sender, EventArgs e)
        {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\mobile.mdb;Jet OLEDB:Database Password=123;Persist Security Info=False";//连接Access数据库的字符串
            using (OleDbConnection conStr = new OleDbConnection(connectionString))
            {
                conStr.Open();//打开数据
                using (OleDbCommand com = conStr.CreateCommand())
                {
                    com.CommandText = "select * from list";
                    using (OleDbDataReader reader = com.ExecuteReader())
                    {
                        //string code = Convert.ToString(reader.GetString(reader.GetOrdinal("code")));
                        string sqlConStr = @"Data Source=HP-PC\SQLEXPRESS;Initial Catalog=login;Integrated Security=True";
                        using (SqlConnection sqlCon = new SqlConnection(sqlConStr))
                        {
                            sqlCon.Open();
                            using (SqlCommand sqlCmd = sqlCon.CreateCommand())
                            {
                                while (reader.Read())//读取数据库里的数据
                                {
                                    string oleNum = Convert.ToString(reader.GetString(reader.GetOrdinal("num")));
                                    string oleCode = Convert.ToString(reader.GetString(reader.GetOrdinal("code")));
                                    string oleCity = Convert.ToString(reader.GetString(reader.GetOrdinal("city")));
string oleCardtype = Convert.ToString(reader.GetString(reader.GetOrdinal("cardtype")));
                                    sqlCmd .CommandText= "insert into T_mobile(Num,Code,City,Cardtype) values (@num,@code,@city,@cardtype)";
                                    SqlParameter anum = new SqlParameter("num",oleNum);
                                    SqlParameter bcode = new SqlParameter("code", oleCode);
                                    SqlParameter ccity=new SqlParameter("city",oleCity);
                                    SqlParameter dcardtype=new SqlParameter("cardtype",oleCardtype);
                                    sqlCmd.Parameters.Add(anum);
                                    sqlCmd.Parameters.Add(bcode);
                                    sqlCmd.Parameters.Add(ccity);
                                    sqlCmd.Parameters.Add(dcardtype);
                                    sqlCmd.ExecuteNonQuery();
                                    sqlCmd.Parameters.Clear();
                                }
                            }
                        }
                    }
                }
            }
            MessageBox.Show("数据导入成功");
        }
    }
}
---------------------- Windows Phone 7手机开发.Net培训、期待与您交流! ---------------------- 详细请查看: http://net.itheima.com/  

原文

---------------------- Windows Phone 7手机开发、 .Net培训、期待与您交流! ----------------------     前几天在黑马论坛上遇到一个网友求手机IP地址的数据,我便回复,网上如果找不到的话

------分隔线----------------------------