婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 將Access數據庫中數據導入到SQL Server中的詳細方法實例

將Access數據庫中數據導入到SQL Server中的詳細方法實例

熱門標簽:濟源人工智能電話機器人價格 內蒙古智能電銷機器人哪家強 怎樣在地圖標注消火栓圖形 地圖標注位置多的錢 百度地圖標注點擊事件 山東防封電銷卡辦理套餐 廈門四川外呼系統 杭州智能電話機器人 泰州手機外呼系統軟件

Default.aspx

復制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true" CodeFile="AccessToSQL.aspx.cs" Inherits="AccessToSQL" %>

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

html xmlns="http://www.w3.org/1999/xhtml">
head runat="server">
    title>無標題頁/title>
    style type="text/css">

        .style1
        {
            height: 16px;
        }
        .style3
        {
            height: 23px;
        }
    /style>
/head>
body>
    form id="form1" runat="server">
    div>

    /div>
    table align="center" border="1" bordercolor="honeydew" cellpadding="0"
        cellspacing="0">
        tr>
            td colspan="2"
                style="FONT-SIZE: 9pt; COLOR: #ffffff; HEIGHT: 16px; BACKGROUND-COLOR: #ff9933; TEXT-ALIGN: center">
                將Access數據庫中數據寫入SQL Server數據庫中/td>
        /tr>
        tr>
            td style="BACKGROUND-COLOR: #ffffcc; TEXT-ALIGN: center">
                asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333"
                    GridLines="None" style="font-size: small" Width="331px">
                    FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                    PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                    SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                    HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    AlternatingRowStyle BackColor="White" />
                /asp:GridView>
            /td>
            td style="WIDTH: 190px; BACKGROUND-COLOR: #ffffcc; TEXT-ALIGN: center">
                asp:GridView ID="GridView1" runat="server" CellPadding="4" Font-Size="9pt"
                    ForeColor="#333333" GridLines="None" Width="228px">
                    FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                    SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                    PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                    HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                    AlternatingRowStyle BackColor="White" />
                /asp:GridView>
            /td>
        /tr>
        tr>
            td style="HEIGHT: 23px; BACKGROUND-COLOR: #ff9900; TEXT-ALIGN: center"
                valign="top">
                asp:Button ID="Button3" runat="server" Font-Size="9pt" onclick="Button1_Click"
                    Text="Access數據寫入SQL數據庫中" />
    asp:Label ID="Label1" runat="server" Text="Label" Visible="False"
                    style="font-size: x-small">/asp:Label>
            /td>
            td style="WIDTH: 190px; HEIGHT: 23px; BACKGROUND-COLOR: #ff9900; TEXT-ALIGN: center">
                asp:Button ID="Button2" runat="server" Font-Size="9pt" onclick="Button2_Click"
                    Text="SQL數據庫中顯示導入的數據" />
            /td>
        /tr>
        /table>
    /form>
/body>
/html>


Default.aspx.cs

復制代碼 代碼如下:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
using System.Data.SqlClient;

public partial class AccessToSQL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AccessLoadData();
        }
    }
    public OleDbConnection CreateCon()
    {
        string strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath("UserScore.mdb") + ";User Id=admin;Password=;";
        OleDbConnection odbc = new OleDbConnection(strconn);
        return odbc;
    }
    public SqlConnection CreateSQLCon()
    {
        string sqlcon = ConfigurationSettings.AppSettings["strCon"];
        SqlConnection mycon = new SqlConnection(sqlcon);
        return mycon;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sql = "";
        OleDbConnection con = CreateCon();//創建數據庫連接
        con.Open();
        DataSet ds = new DataSet(); //創建數據集
        sql = "select * from Score";
        OleDbDataAdapter myCommand = new OleDbDataAdapter(sql,con);//創建數據適配器
        myCommand.Fill(ds, "Score");
        myCommand.Dispose();
        DataTable DT = ds.Tables["Score"];
        con.Close();
        myCommand.Dispose();
        for (int j = 0; j DT.Rows.Count; j++)//循環ACCESS中數據獲取相應信息
        {
            string sqlstr = "";
            string ID = DT.Rows[j][0].ToString();
            string UserName = DT.Rows[j][1].ToString();
            string PaperName = DT.Rows[j][2].ToString();
            string UserScore = DT.Rows[j][3].ToString();
            string ExamTime = DT.Rows[j][4].ToString();
            string selsql = "select count(*) from AccessToSQL where 用戶姓名='" + UserName + "'";
            if (ExScalar(selsql) > 0)//判斷數據是否已經添加
            {
                Label1.Visible = true;
                Label1.Text = "script language=javascript>alert('該Access數據庫中數據已經導入SQL數據庫中!');location='AccessToSQL.aspx';/script>";
            }
            else
            {
                string AccessPath = Server.MapPath("UserScore.mdb");//獲取ACCESS數據庫路徑
                //應用OPENROWSET函數訪問 OLE DB 數據源中的遠程數據所需的全部連接信息
                sqlstr = "insert into AccessToSQL(ID,用戶姓名,試卷,成績,考試時間)Values('" + ID + "','" + UserName + "','" + PaperName + "','" + UserScore + "','" + ExamTime + "')";
                sqlstr += "select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','" + AccessPath + "';'admin';'',Score)";
                SqlConnection conn = CreateSQLCon();
                conn.Open();
                SqlCommand mycom = new SqlCommand(sqlstr, conn);
                mycom.ExecuteNonQuery();//執行添加操作
                if (j == DT.Rows.Count - 1)
                {
                    Label1.Visible = true;
                    Label1.Text = "script language=javascript>alert('數據導入成功.');location='AccessToSQL.aspx';/script>";
                }
                else
                {
                    Label1.Visible = true;
                    Label1.Text = "script language=javascript>alert('數據導入失敗.');location='AccessToSQL.aspx';/script>";
                }
                conn.Close();
            }
        }

    }
    public void AccessLoadData()
    {
        OleDbConnection myConn = CreateCon();
        myConn.Open();   //打開數據鏈接,得到一個數據集    
        DataSet myDataSet = new DataSet();   //創建DataSet對象    
        string StrSql = "select   *   from  Score";
        OleDbDataAdapter myCommand = new OleDbDataAdapter(StrSql, myConn);
        myCommand.Fill(myDataSet, "Score");
        GridView2.DataSource = myDataSet;
        GridView2.DataBind();
        myConn.Close();
    }
    public int ExScalar(string sql)
    {
        SqlConnection conn = CreateSQLCon();
        conn.Open();
        SqlCommand com = new SqlCommand(sql, conn);
        return Convert.ToInt32(com.ExecuteScalar());
        conn.Close();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string sqlstr = "select * from AccessToSQL";
        SqlConnection conn = CreateSQLCon();
        conn.Open();
        SqlCommand mycom = new SqlCommand(sqlstr, conn);
        SqlDataReader dr = mycom.ExecuteReader();
        dr.Read();
        if (dr.HasRows)
        {
            GetDataSet(sqlstr);
        }
        else
        {
            Label1.Visible = true;
            Label1.Text = "script language=javascript>alert('數據庫中沒有數據信息,請先導入再查詢!');location='AccessToSQL.aspx';/script>";
        }
        dr.Close();
        conn.Close();
    }
    public DataSet GetDataSet(string sqlstr)
    {
        SqlConnection conn = CreateSQLCon();
        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, conn);
        DataSet ds = new DataSet();
        myda.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        return ds;
    }
}

您可能感興趣的文章:
  • SQL Server中的數據復制到的Access中的函數
  • Access轉Sql Server問題 實例說明
  • Sql Server、Access數據排名的實現方法(例如:成績排名)
  • SQLServer與Access常用SQL函數區別
  • SQL 隨機查詢 包括(sqlserver,mysql,access等)
  • 在ACCESS和SQL Server下Like 日期類型查詢區別
  • Access和SQL Server里面的SQL語句的不同之處
  • asp.net下Oracle,SQL Server,Access萬能數據庫通用類
  • SQL SERVER 與ACCESS、EXCEL的數據轉換方法分享
  • 八步解決ACCESS自動編號問題(將SQL SERVER 2000數據庫,轉換為ACCESS數據庫)
  • 將ACCESS數據庫遷移到SQLSERVER數據庫兩種方法(圖文詳解)
  • sqlserver,sqlite,access數據庫鏈接字符串整理
  • 自己動手把ACCESS轉換到SQLSERVER的方法
  • Access 導入到SQL Server 2005的方法小結
  • JavaScript使用ActiveXObject訪問Access和SQL Server數據庫
  • SQL Server數據復制到的Access兩步走

標簽:喀什 新鄉 朝陽 洛陽 臺州 周口 百色 朔州

巨人網絡通訊聲明:本文標題《將Access數據庫中數據導入到SQL Server中的詳細方法實例》,本文關鍵詞  將,Access,數據庫,中,數據,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《將Access數據庫中數據導入到SQL Server中的詳細方法實例》相關的同類信息!
  • 本頁收集關于將Access數據庫中數據導入到SQL Server中的詳細方法實例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 台东县| 苍梧县| 抚顺县| 千阳县| 喀喇沁旗| 徐州市| 喀喇沁旗| 江津市| 临沂市| 精河县| 孝义市| 滦南县| 洪雅县| 乌兰浩特市| 汉川市| 安泽县| 彭泽县| 田阳县| 白河县| 廉江市| 凤冈县| 策勒县| 三穗县| 丰顺县| 武冈市| 碌曲县| 正宁县| 临漳县| 沭阳县| 定西市| 泾阳县| 永康市| 姜堰市| 襄城县| 教育| 夏津县| 香河县| 怀安县| 独山县| 塘沽区| 汉中市|