Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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Óï¾ä´óÈ«

¡¡SQL·ÖÀࣺ
¡¡¡¡DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
¡¡¡¡DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
¡¡¡¡DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
¡¡¡¡Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
¡¡¡¡1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
¡¡¡¡2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý ......

SQL distinctÓ÷¨¡¡¼òµ¥group by ÃüÁî


distinctÕâ¸ö¹Ø¼ü×ÖÓÃÀ´¹ýÂ˵ô¶àÓàµÄÖØ¸´¼Ç¼ֻ±£ÁôÒ»Ìõ£¬µ«ÍùÍùÖ»ÓÃËüÀ´·µ»Ø²»Öظ´¼Ç¼µÄÌõÊý£¬¶ø²»ÊÇÓÃËüÀ´·µ»Ø²»ÖؼǼµÄËùÓÐÖµ¡£ÆäÔ­ÒòÊÇdistinctÖ»ÓÐÓöþÖØÑ­»·²éѯÀ´½â¾ö£¬¶øÕâÑù¶ÔÓÚÒ»¸öÊý¾ÝÁ¿·Ç³£´óµÄÕ¾À´Ëµ£¬ÎÞÒÉÊÇ»áÖ±½ÓÓ°Ï쵽ЧÂʵġ£
ÏÂÃæÏÈÀ´¿´¿´Àý×Ó£º
table±í
×Ö¶Î1      ×Ö¶ ......

SQL outputʹÓÃ

SQL°æ£º
alter proc testguo
(
    @cityid int,
    @cityname nvarchar(100) output
)
as
select @cityname =  city_name from BA_Hot_City where cityid = @cityid
select @cityname
go
declare @cityname nvarchar(100)
exec testguo 1,@cityname output
ÁíÒ»°æ£º
ht ......

ÔÚasp.netÖÐʹÓÃswfuploadÖУ¬ÖÐÎÄÎļþÃûÂÒÂëµÄ½â¾ö

´ÓcsdnÏÂÔØÁËʹÓð¸Àý£¬µ«·¢ÏֺܶàÈËÒÀÈ»»áÓöµ½ÖÐÎÄÎļþÃûÂÒÂëµÄÎÊÌ⣬ԭÒòÈçÏ£º
Ò»°ãÔÚµ¥Î»µÄ¿ª·¢ÖÐÔÚxml.configÎļþÖж¼Ê¹ÓÃgb2312£¬ÈçÏ£º
  <globalization responseEncoding="gb2312" requestEncoding="gb2312"/>
¶øswfuploadÊǰ´ÕÕutf-8À´±àÂëµÄ£¬ËùÒÔÄãÐèÒªÔÚʹÓÃsufuploadµÄ³ÌÐòÎļþĿ¼ÏÂÖØÐ ......

ASP.NET DBHelperÀà

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 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ