最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

將Access數(shù)據(jù)庫中數(shù)據(jù)導(dǎo)入到SQL Server中的詳細(xì)方法實例

 更新時間:2013年03月19日 21:18:21   作者:  
將Access數(shù)據(jù)庫中數(shù)據(jù)導(dǎo)入到SQL Server中的詳細(xì)方法實例,需要的朋友可以參考一下

Default.aspx

復(fù)制代碼 代碼如下:

<%@ 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>無標(biāo)題頁</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數(shù)據(jù)庫中數(shù)據(jù)寫入SQL Server數(shù)據(jù)庫中</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數(shù)據(jù)寫入SQL數(shù)據(jù)庫中" />
    <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數(shù)據(jù)庫中顯示導(dǎo)入的數(shù)據(jù)" />
            </td>
        </tr>
        </table>
    </form>
</body>
</html>


Default.aspx.cs

復(fù)制代碼 代碼如下:

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();//創(chuàng)建數(shù)據(jù)庫連接
        con.Open();
        DataSet ds = new DataSet(); //創(chuàng)建數(shù)據(jù)集
        sql = "select * from Score";
        OleDbDataAdapter myCommand = new OleDbDataAdapter(sql,con);//創(chuàng)建數(shù)據(jù)適配器
        myCommand.Fill(ds, "Score");
        myCommand.Dispose();
        DataTable DT = ds.Tables["Score"];
        con.Close();
        myCommand.Dispose();
        for (int j = 0; j < DT.Rows.Count; j++)//循環(huán)ACCESS中數(shù)據(jù)獲取相應(yīng)信息
        {
            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)//判斷數(shù)據(jù)是否已經(jīng)添加
            {
                Label1.Visible = true;
                Label1.Text = "<script language=javascript>alert('該Access數(shù)據(jù)庫中數(shù)據(jù)已經(jīng)導(dǎo)入SQL數(shù)據(jù)庫中!');location='AccessToSQL.aspx';</script>";
            }
            else
            {
                string AccessPath = Server.MapPath("UserScore.mdb");//獲取ACCESS數(shù)據(jù)庫路徑
                //應(yīng)用OPENROWSET函數(shù)訪問 OLE DB 數(shù)據(jù)源中的遠(yuǎn)程數(shù)據(jù)所需的全部連接信息
                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();//執(zhí)行添加操作
                if (j == DT.Rows.Count - 1)
                {
                    Label1.Visible = true;
                    Label1.Text = "<script language=javascript>alert('數(shù)據(jù)導(dǎo)入成功.');location='AccessToSQL.aspx';</script>";
                }
                else
                {
                    Label1.Visible = true;
                    Label1.Text = "<script language=javascript>alert('數(shù)據(jù)導(dǎo)入失敗.');location='AccessToSQL.aspx';</script>";
                }
                conn.Close();
            }
        }

    }
    public void AccessLoadData()
    {
        OleDbConnection myConn = CreateCon();
        myConn.Open();   //打開數(shù)據(jù)鏈接,得到一個數(shù)據(jù)集    
        DataSet myDataSet = new DataSet();   //創(chuàng)建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('數(shù)據(jù)庫中沒有數(shù)據(jù)信息,請先導(dǎo)入再查詢!');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;
    }
}

相關(guān)文章

  • Asp.net給站點某目錄增加Aspnet用戶

    Asp.net給站點某目錄增加Aspnet用戶

    Asp.net給站點某目錄增加Aspnet用戶...
    2006-09-09
  • asp.net下PageMethods使用技巧

    asp.net下PageMethods使用技巧

    ASP.net AjAX中的PageMethods可以將靜態(tài)頁方法添加到 ASP.NET 頁中并將其用作 Web 方法。然后,無需創(chuàng)建單獨的 .asmx 文件即可從該頁中的腳本調(diào)用這些方法,就好像這些方法是 Web 服務(wù)的一部分。特別是在一些交互流程不復(fù)雜而調(diào)用次數(shù)和方法又比較多的情況下更為方便。因為PageMethods不需要我們再添加另外的WEB服務(wù)或Page來處理請求。
    2008-03-03
  • 用 Asp.Net 建立一個在線 RSS 新聞聚合器的方法

    用 Asp.Net 建立一個在線 RSS 新聞聚合器的方法

    用 Asp.Net 建立一個在線 RSS 新聞聚合器的方法...
    2007-04-04
  • ASP.NET Eval進(jìn)行數(shù)據(jù)綁定的方法

    ASP.NET Eval進(jìn)行數(shù)據(jù)綁定的方法

    ASP.NET Eval在數(shù)據(jù)綁定方面的應(yīng)用是眾所周知的,不過技術(shù)在發(fā)展,當(dāng)ASP.NET Eval 1.1變成ASP.NET Eval 2.0的時候,在操作的時候會有什么變化呢?
    2013-04-04
  • ASP.NET Core利用UrlFirewall對請求進(jìn)行過濾的方法示例

    ASP.NET Core利用UrlFirewall對請求進(jìn)行過濾的方法示例

    這篇文章主要給大家介紹了關(guān)于ASP.NET Core利用UrlFirewall對請求進(jìn)行過濾的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • asp.net?Core中同名服務(wù)注冊的實現(xiàn)代碼

    asp.net?Core中同名服務(wù)注冊的實現(xiàn)代碼

    Asp.Net?Core中自帶了容器,同時也可以使用AutoFac替換掉默認(rèn)的容器,以下為兩種方式同名服務(wù)的注冊實現(xiàn),對asp.net?Core服務(wù)注冊的實現(xiàn)代碼感興趣的朋友一起看看吧
    2022-03-03
  • ASP.NET Core Zero使用Power Tool工具

    ASP.NET Core Zero使用Power Tool工具

    這篇文章介紹了ASP.NET Core Zero使用Power Tool工具的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-02-02
  • ASP.NET?MVC實現(xiàn)樹形導(dǎo)航菜單

    ASP.NET?MVC實現(xiàn)樹形導(dǎo)航菜單

    這篇文章介紹了ASP.NET?MVC實現(xiàn)樹形導(dǎo)航菜單的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-09-09
  • asp.net core MVC之實現(xiàn)基于token的認(rèn)證

    asp.net core MVC之實現(xiàn)基于token的認(rèn)證

    這篇文章主要介紹了asp.net core MVC之實現(xiàn)基于token的認(rèn)證,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05

最新評論

海城市| 长丰县| 青铜峡市| 思茅市| 扶余县| 临高县| 景宁| 四平市| 海兴县| 万安县| 宣恩县| 米易县| 万盛区| 仁布县| 罗源县| 时尚| 正蓝旗| 峨山| 黔东| 吐鲁番市| 高密市| 高邮市| 奈曼旗| 石林| 雷州市| 仙居县| 哈尔滨市| 湘西| 莒南县| 渭南市| 霞浦县| 隆子县| 绍兴县| 同心县| 东至县| 仁布县| 南皮县| 无棣县| 河源市| 库车县| 唐山市|