ASP.NET Excelµ¼Èëµ½SQL ServerÊý¾Ý¿â
ASP.NET Excelµ¼Èëµ½SQL ServerÊý¾Ý¿â
Ìṩ°ÑExcelÀïµÄÊý¾Ýµ¼Èëµ½SQL Server Êý¾Ý¿â£¬Ç°ÌáÊÇExcelÀïµÄ×Ö¶ÎÔÚSql Server±íÀﶼÓУ¬²»È»»á³öÏÖ´íÎó¡£×¢ÊͺÜÏêϸŶ£¡ÒªÒýÓõÄÃüÃû¿Õ¼äÊÇ£º
using System.Data.OleDb;
using System.Data.SqlClient;
//²Ù×÷Àà
public class ExcelToSQL
{
//string SqlConnectionString = "Server=(local);Initial Catalog=Test;Integrated Security=True";
public SqlConnection sqlcon; //´´½¨SQLÁ¬½Ó
public SqlCommand sqlcom; //´´½¨SQLÃüÁî¶ÔÏó
public ExcelToSQL()
{
DataOperation dataOperation = new DataOperation(); //Óõ½Æ½Ì¨µÄº¯Êý£¬¾ÍÊdzõʼ»¯SqlConnection¶ÔÏó
DBUnit dbUnit = dataOperation.GetDbUnit();
sqlcon = (SqlConnection)dbUnit.cnt;
if (sqlcon.State.ToString() == "Open")
sqlcon.Close();
}
public int ImportSql(string excelPath, string tableName) //µ¼ÈëµÄExcelµÄ·¾¶£¬Êý¾Ý¿âÀïµÄ±íÃû
{
if (!TableExist(tableName)) //±íÃûÊÇ·ñ´æÔÚ
return (int)ImportState.tableNameError;
DataTable dt = ExcelToDataTable(excelPath);
if (dt == null)
{
&nbs
Ïà¹ØÎĵµ£º
¡¡SQL·ÖÀࣺ
¡¡¡¡DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
¡¡¡¡DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
¡¡¡¡DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
¡¡¡¡Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
¡¡¡¡1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
¡¡¡¡2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý ......
distinctÕâ¸ö¹Ø¼ü×ÖÓÃÀ´¹ýÂ˵ô¶àÓàµÄÖظ´¼Ç¼ֻ±£ÁôÒ»Ìõ£¬µ«ÍùÍùÖ»ÓÃËüÀ´·µ»Ø²»Öظ´¼Ç¼µÄÌõÊý£¬¶ø²»ÊÇÓÃËüÀ´·µ»Ø²»ÖؼǼµÄËùÓÐÖµ¡£ÆäÔÒòÊÇdistinctÖ»ÓÐÓöþÖØÑ»·²éѯÀ´½â¾ö£¬¶øÕâÑù¶ÔÓÚÒ»¸öÊý¾ÝÁ¿·Ç³£´óµÄÕ¾À´Ëµ£¬ÎÞÒÉÊÇ»áÖ±½ÓÓ°Ï쵽ЧÂʵġ£
ÏÂÃæÏÈÀ´¿´¿´Àý×Ó£º
table±í
×Ö¶Î1 ×Ö¶ ......
SQL ½Ì³Ì
1£©SQL ¼ò½é
SQL(Structured Query Language£¬½á¹¹²éѯÓïÑÔ)ÊÇÒ»¸ö¹¦ÄÜÇ¿´óµÄÊý¾Ý¿âÓïÑÔ¡£SQLͨ³£Ê¹ÓÃÓÚÊý¾Ý¿âµÄͨѶ¡£ANSI£¨ÃÀ¹ú¹ú¼Ò±ê׼ѧ»á£©Éù³Æ£¬SQLÊǹØϵÊý¾Ý¿â¹ÜÀíϵͳµÄ±ê×¼ÓïÑÔ¡£SQLÓï¾äͨ³£ÓÃÓÚÍê³ÉһЩÊý¾Ý¿âµÄ²Ù×÷ÈÎÎñ£¬±ÈÈçÔÚÊý¾Ý¿âÖиüÐÂÊý¾Ý£¬»òÕß´ÓÊý¾Ý¿âÖмìË÷Êý¾Ý¡£Ê¹ÓÃSQLµÄ³£¼û¹ØϵÊý¾Ý¿â¹ ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data.Common;
using System.Data;
namespace DownData.dal
{
public static class DBHelper
{
private stati ......
1. ͼƬÎÊÌâ
·Ç³£ºÃ½â¾ö
<img runat="server" src="~/images/ad468x60.gif" alt="" />
¼ÓÉÏrunat="server" £¬Â·¾¶Ê¹Óþø¶Ô·¾¶~/»ù±¾ÉϾÍOKÁË¡£
2. CSSÎļþÒýÓÃ
<link rel="stylesheet" type="text/css" href="style.css" />
ÕâÀïÉñÆæµÄ¾ÍÊÇlinkµÄÎļþµÄhrefÊÇËæ×ű»·ÃÎÊÎļþµÄĿ¼½á¹¹×Ô¶¯µ÷Õû£¬Ëµ°×Á˾ ......