顯示具有 ASP.NET應用 標籤的文章。 顯示所有文章
顯示具有 ASP.NET應用 標籤的文章。 顯示所有文章

2020年4月29日 星期三

在GridView中加入自動編號的序號

參考: https://blog.xuite.net/xiaolian/blog/46204394-%E5%9C%A8GridView%E4%B8%AD%E5%8A%A0%E5%85%A5%E8%87%AA%E5%8B%95%E7%B7%A8%E8%99%9F%E7%9A%84%E5%BA%8F%E8%99%9F

在Aspx檔案中GridView表格內插入一個欄位,在第一欄加上TemplateField的欄位,語法如下:

流水號從第一筆編起
  <asp:TemplateField HeaderText="序號">
          <ItemTemplate>
             <%#GridView1.PageIndex * GridView1.PageSize + GridView1.Rows.Count + 1%>
           </ItemTemplate>
           <HeaderStyle Wrap="False"  />
            <ItemStyle  HorizontalAlign="Center" VerticalAlign="Middle" />
  </asp:TemplateField>

OR

  <asp:TemplateField HeaderText="序號">
         <ItemTemplate>
            <%#Container.DataItemIndex + 1%>
         </ItemTemplate>
         <HeaderStyle Wrap="False"  />
         <ItemStyle  HorizontalAlign="Center" VerticalAlign="Middle" />
  </asp:TemplateField>


流水號每頁從1編起
   <asp:TemplateField HeaderText="序號">
           <ItemTemplate>
              <%#Container.DisplayIndex + 1%>
            </ItemTemplate>
            <HeaderStyle Wrap="False"  />
            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
   </asp:TemplateField>
 

2019年3月6日 星期三

gridview選取出現跳動解決方法

在 PostBack後會回到最頂端的位置,有三個方式可讓單頁停留在原來位置

在 PostBack後會回到最頂端的位置,有三個方式可讓單頁停留在原來位置

1.
Web.config

//在<system.web></system.web>之間增加節點
<pages maintainScrollPositionOnPostBack="true"></pages>

2.
.aspx

<@page MaintainScrollPositionOnPostback="true" .......>

3.
.cs

Page.MaintainScrollPositionOnPostBack = true;
code轉換

2019年2月15日 星期五

content 內加入jquery

<script src="Scripts/bootstrap-datepicker.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#<% =DateText.ClientID %>').datepicker({
                changeMonth: true,
                changeYear: true,
                format: 'yyyy/mm/dd',

            });
    </script>


code轉換

2019年1月24日 星期四

SQL 匯入EXCEL 出現錯誤




問題: microsoft.ace.oledb.12.0 提供者並未登錄於畚箕電腦上 問題解決

解決:

安裝
Microsoft Access Database Engine 2010 Redistributable
http://www.microsoft.com/downloads/details.aspx?familyid=C06B8369-60DD-4B64-A44B-84B371EDE16D&displaylang=en

2007 Office system 驅動程式:資料連線元件
http://www.microsoft.com/downloads/zh-tw/confirmation.aspx?displaylang=zh-tw&FamilyID=7554f536-8c28-4598-9b72-ef94e038c891



2018年1月15日 星期一

ASP.NET和SQL 語法



外部連接
SELECT A1.Store_Name, SUM(A2.Sales) SALES
FROM Georgraphy A1, Store_Information A2
WHERE A1.Store_Name = A2.Store_Name (+)
GROUP BY A1.Store_Name;

強制分辨大小寫
SELECT * FROM MEMBER_TABLE WHERE cName COLLATE Latin1_General_CS_AI = 'John'

  1. Case Sensitivity (CS):強制視別大小寫
  2. Case Insensitive (CI):不強制視別大小寫
  3. Accent Sensitivity (AS):強制視別音腔,通常出現在歐洲語系
  4. Accent Insensitive (AI):不強制視別音腔
  5. Kana Sensitivity (KS):強制視別平假、片假名
  6. Kana Insensitive (KI):不強制視別平假、片假名
  7. Width Sensitivity (WS):強制視別中文的全型字與英文字,例如abc與abc是不一樣的
  8. Width Insensitive (WI):不強制視別中文的全型字與英文字

模糊查詢
一般模糊語句如下:

Select 欄位 FROM 表 Where 某欄位 Like 條件


其中關於條件,SQL提供了四種匹配模式:

1,%:表示任意0個或多個字元。可匹配任意類型和長度的字元,有些情況下若是中文,請使用兩個百分號(%%)表示。

 Select * FROM [user] Where u_name LIKE '%三%'

將會把u_name為「張三」,「張貓三」、「三腳貓」,「唐三藏」等等有「三」的記錄全找出來。

另外,如果需要找出u_name中既有「三」又有「貓」的記錄,請使用and條件
Select * FROM [user] Where u_name LIKE '%三%' AND u_name LIKE '%貓%'

若使用 程式碼
Select * FROM [user] Where u_name LIKE '%三%貓%'
雖然能搜索出「三腳貓」,但不能搜索出符合條件的「張貓三」。

2,_: 表示任意單個字元。匹配單個任一字元,它常用來限制運算式的字元長度語句:

比如 
Select * FROM [user] Where u_name LIKE '_三_'
只找出「唐三藏」這樣u_name為三個字且中間一個字是「三」的;

再比如
Select * FROM [user] Where u_name LIKE '三__';
只找出「三腳貓」這樣name為三個字且第一個字是「三」的;


3,[ ]:表示括弧內所列字元中的一個(類似正則運算式)。指定一個字元、字串或範圍,要求所匹配物件為它們中的任一個。

比如
Select * FROM [user] Where u_name LIKE '[張李王]三'
將找出「張三」、「李三」、「王三」(而不是「張李王三」);

如 [ ] 內有一系列字元(01234、abcde之類的)則可略寫為「0-4」、「a-e」
Select * FROM [user] Where u_name LIKE '老[1-9]'
將找出「老1」、「老2」、......、「老9」;

4,[^ ] :表示不在括弧所列之內的單個字元。其取值和 [] 相同,但它要求所匹配物件為指定字元以外的任一個字元。

比如
Select * FROM [user] Where u_name LIKE '[^張李王]三'
將找出不姓「張」、「李」、「王」的「趙三」、「孫三」等;

Select * FROM [user] Where u_name LIKE '老[^1-4]'
將排除「老1」到「老4」,尋找「老5」、「老6」、......

5,查詢內容包含萬用字元時

由於萬用字元的緣故,導致我們查詢特殊字元「%」、「_」、「[」的語句無法正常實現,而把特殊字元用「[ ]」括起便可正常查詢。據此我們寫出以下函數:

Asp的替換語句,可以參考一下

function sqlencode(str)
str=replace(str,"[","[[]") '此句一定要在最前
str=replace(str,"_","[_]")
str=replace(str,"%","[%]")
sqlencode=str
end function

在查詢前將待查字串先經該函數處理即可。


該文章轉載自德仔工作室:HTTP://www.dezai.cn/Article_Show.asp?ArticleID=23862


1.INSERT INTO SELECT語法

  語法為:Insert into Table2(field1,field2,...) select value1,value2,... from Table1
  要求目標表Table2必須存在,由於目標表Table2已經存在,所以我們除了插入源表Table1的字段外,才可以插入常量。

2.SELECT INTO FROM語法

  語法為:SELECT vale1, value2 into Table2 from Table1

  要求目標表Table2不存在,因為在插入時會自動創建表Table2,並將Table1中指定字段數據復制到 Table2中。

---------------------------

DataReader 擷取資料



asp .net 連接sql (ExecuteReader)

查詢  →   command.ExecuteReader();         回傳sqlDataReader

新增、修改、刪除 →   command.ExecuteNonQuery();           回傳int

2016年9月2日 星期五

Your login attempt was not successful. Please try again.



http://forums.asp.net/t/959371.aspx?Your+login+attempt+was+not+successful+Please+try+again+




1. In Windows Explorer, right-click on your App_Data folder (I'm supposing you're using MDF files in App_Data folder) and go toProperties>Security tab. (If you're using WXPPro and can't see this one, just go Tools > Folder Options > View tab and disable "Simple Sharing" option - the last one. This option is not available in WXPHome)
2. Add user **YOURMACHINENAME**\ASPNET.
3. Grant to this user the Modify/Write permission.
4. Apply to all subsequent files in folder.
* Maybe you must need to check also the ASPNET user hasn't denied the write permission.
This worked fine for me, hope this helps.
----------------------------------------------------------------
i bought the book Microsoft Visual C# 2008 step by step $39.99 (Amazon) and i was having the same problems as everyone else
while reading the book i came acrross this code in chapter 29
just open your web config file and insert the following code as it is written at the header authentication mode
<authentication mode="Forms">
<forms loginUrl="LoginForm.aspx" timeout="5"
cookieless="AutoDetect" protection="All" />
</authentication>
the top line will look like this  <authentication mode="Forms" />           remove the /
the url that is inserted is the name of my login page obviously if your login page is named something different
then insert your login url also if you are using visual studio use the built in web pages to set up ASP .NET configuration
you will find this in your solution explorer just click the last icon on the right
-----------------------------------------------------------------------

Configuring ASP.NET 2.0 Application Services to use SQL Server 2000 or SQL Server 2005

One question I’ve seen asked a few times by people over the last few weeks is “how do I setup the new ASP.NET Membership, Role Management, and Personalization services to use a regular SQL Server instead of SQL Express?” This blog entry walks you though a few simple steps on how to-do this.

Quick Review: What are the new ASP.NET 2.0 Application Services?

ASP.NET 2.0 includes a number of built-in “building block” application services.  We call them “building blocks” because they are useful core frameworks for enabling super-common scenarios with web applications today – and as a result can provide significant productivity wins and time-savings for developers.

They include: a membership API for managing usernames/passwords and secure credential management, a roles API that supports mapping users into logical groups, a profile API for storing arbitrary properties about both authenticated and anonymous users visiting a web site (for example: their zipcode, gender, theme preference, etc), a personalization API for storing control customization preferences (this is most often used with the WebPart features in ASP.NET 2.0), a health monitoring API that can track and collect information about the running state and any errors that occur within a web application, and a site navigation API for defining hierarchy within an application and constructing navigation UI (menus, treeviews, bread-crumbs) that can be context specific based on where the current incoming user is in the site.

The ASP.NET Application Service APIs are designed to be pluggable and implementation agnostic, which means that the APIs do not hardcode the details of where data is stored with them.  Instead, the APIs call into “providers”, which are classes that implement a specific “provider contract” – which is defined as an abstract class with a defined set of methods/properties that the API expects to be implemented.

ASP.NET 2.0 ships with a number of built-in providers including: a SQL Express provider for going against local SQL Express Databases, SQL 2000/2005 providers that work against full-blown SQL Servers, an Active Directory Provider that can go against AD or ADAM implementations, and in the case of site navigation an XML provider that can bind against XML files on the file-system.

The beauty of the model is that if you don’t like the existing providers that ship in the box, or want to integrate these APIs against existing data-stores you are already using, then you can just implement a provider and plug it in.  For example: you might already have an existing database storing usernames/passwords, or an existing LDAP system you need to integrate with.  Just implement the MembershipProvider contract as a class and register it in your application’s web.config file (details below), and all calls to the Membership API in ASP.NET will delegate to your code.

Default SQL Express Providers

Out of the box, most of the ASP.NET 2.0 application services are configured to use the built-in SQL Express provider.  This provider will automatically create and provision a new database for you the first time you use one of these application services, and provides a pretty easy way to get started without a lot of setup hassles (just have SQL Express on the box and you are good to go).  Note that SQL Express databases can also be upgraded to run in the context of full-blown SQL Server instances – so apps built using SQL Express for development can easily be upgraded into a high-volume, clustered, fail-over secure 8P SQL box when your app becomes wildly successful.

How do I change the providers to use SQL Server Instead of SQL Express?

If you want to use a full-blown SQL Server 2000 or SQL Server 2005 database instance instead of SQL Express, you can follow the below steps:

Step 1: Create or obtain a blank SQL database instance

In this step you’ll want to create or obtain a connection string to a standard SQL database instance that is empty.

Step 2: Provision your SQL database with the ASP.NET schemas

Open a command-line window on your system and run the aspnet_regsql.exe utility that is installed with ASP.NET 2.0 in under your C:\WINDOWS\Microsoft.NET\Framework\v2.0.xyz directory. 

Note that this utility can be run in either a GUI based mode or with command-line switches (just add a -? flag to see all switch options).

Using this wizard you can walkthrough creating the schema, tables and sprocs for the built-in SQL providers that come with ASP.NET 2.0.  The below screens show the step-by-step walkthrough of this:

 

 

 

 

 

Once you have finished walking through the wizard, all the database schema + sprocs to support the application services will have been installed and configured (note: if your DBA wants to see exactly what is going on behind the covers, we also ship the raw .sql files underneath the above framework directory, and your DBA can walkthrough them and/or run them manually to install the DB).

Step 3: Point your web.config file at the new SQL Database

ASP.NET 2.0 now supports a new section in your web.config file called “” which (not too surprisingly) are used to store connection strings.  One nice thing from an administration perspective is that the new ASP.NET Admin MMC Snap-in now provides a GUI based way to configure and manage these:


 
ASP.NET 2.0 also now supports encrypting any section stored in web.config files -- so you can also now securely store private data like connectionstrings without having to write any encryption code of your own. 

ASP.NET 2.0 ships with a built-in connection string called “LocalSqlServer” which by default is configured to use a SQL Express database, and which by default the Membership, Roles, Personalization, Profile and Health Monitoring services are configured to use.

The easiest way to have your application automatically take advantage of your newly created SQL database is to just replace the connectionstring value of this “LocalSqlServer” setting in your app’s local web.config.

For example, if I created my database on the local machine in an “appservicesdb” database instance and was connecting using Windows Integrated security, I would change my local web.config file to specify this:


    
        
        Data Source=localhost;Initial Catalog=appservicesdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
    


Hit save, and all of the built-in application services are now using your newly created and defined SQL Server database.

Note: The one downside with the above approach is that I’m re-using the “LocalSqlServer” connection string name – which will feel weird if/when I deploy my database on another machine.  If I wanted to name it with my own connection string name, I could do this simply by adding a completely new connection-string, and then pointing the existing providers to use the new connection-string name in place of the default LocalSqlServer one. 

Hope this helps,

Scott

P.S. In some future blog post I’ll walkthrough actually using some of the above new APIs.

2016年8月16日 星期二

2016年8月4日 星期四

在ASP.NET的sessionState的三種屬性


from: https://dotblogs.com.tw/boei/2010/07/06/16414
摘要:在ASP.NET的sessionState的三種屬性
1.InProc(預設):也就是將Session保存在Process裡面(IIS5是aspnet_wp.exe,而IIS6是W3wp.exe),這個Process算是不穩定,在某些事件發生時,Process會重新啟動。在web.config的設定:
1  <configuration>  
2      <system.web>  
3             <sessionState   mode="InProc"  
4                  timeout="20"  
5                  cookieless="UseCookies">  
6             </sessionState>  
7      </system.web>  
8 </configuration>
2.StateServer:本機的一個服務,可以在系統服務裡看到服務名為ASP.NET State Service的服務,預設下是不啟動的。當我們設定mode為StateServer之後,要在服務那邊手動將該服務啟動喔。在web.config的設定:
1   <configuration>     
2      <system.web>  
3            <sessionState mode="StateServer" timeout="500"       
4            stateConnectionString="tcpip=127.0.0.1:42424"/>     
5      </system.web>  
6  </configuration>
3.SQLServer:將 session 存於 SqlServer 資料庫中,必需要有ASPState資料庫,所以要使用 aspnet_regiis.exe 工具來新增,步驟如下:
  (1.)新增 ASPState 資料庫:進入命令模式視窗輸入 aspnet_regsql.exe -S ServerName -E -ssadd -sstype p
  (2.)如果要移除:進入命令模式視窗輸入aspnet_regsql.exe -S ServerName -E -ssremove
  (3.)在web.config的設定:
1   <configuration>     
2      <system.web>  
3             <sessionState mode="SQLServer"  
4                        sqlCommandTimeout="30"  
5                        sqlConnectionString="data  source=localhost;Integrated            
6                        Security=SSPI">  
7              </sessionState>  
8      </system.web>  
9  </configuration>