台灣最大程式設計社群網站
線上人數
2720
 
會員總數:246323
討論主題:189853
歡迎您免費加入會員
討論區列表 >> ASP.NET >> DetailsView新增的問題
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
DetailsView新增的問題
價值 : 50 QP  點閱數:1001 回應數:2
樓主

joe
門外漢
0 4
84 2
發送站內信

不好意思,我是新手想請教各位DetailsView新增的問題,我的資料庫是access 2016,在網頁上放置了一個DetailsView,全部使用內部點選功能,並未寫任何一行程式,可是在新增完時按下插入鍵就會出現下面的錯誤訊息 , 不知是什麼問題請大家幫幫忙,謝謝!


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

您嘗試指定 Null 值給一個不是 Variant 資料類型的變數。
描述: 在執行目前 Web 要求的過程中發生未處理的例外狀況。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。

例外狀況詳細資訊: System.Data.OleDb.OleDbException: 您嘗試指定 Null 值給一個不是 Variant 資料類型的變數。

原始程式錯誤:


在執行目前 Web 要求期間,產生未處理的例外狀況。如需有關例外狀況來源與位置的資訊,可以使用下列的例外狀況堆疊追蹤取得。

堆疊追蹤:



[OleDbException (0x80004005): 您嘗試指定 Null 值給一個不是 Variant 資料類型的變數。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1140968
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +208
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +162
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +107
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +392
System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +399
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +100
System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) +364
System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +621
System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +89
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +82
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +161
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9776062
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639

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

程式碼:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SamsungRM2.aspx.vb" Inherits="samsung_RM_WEB.SamsungRM2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="識別碼" DataSourceID="SqlDataSource1" Height="263px" Width="386px">
<EditItemTemplate>
識別碼:
<asp:Label ID="識別碼Label1" runat="server" Text='<%# Eval("識別碼") %>' />
<br />
姓名:
<asp:TextBox ID="姓名TextBox" runat="server" Text='<%# Bind("姓名") %>' />
<br />
RM日期:
<asp:TextBox ID="RM日期TextBox" runat="server" Text='<%# Bind("RM日期") %>' />
<br />
領用帳號:
<asp:TextBox ID="領用帳號TextBox" runat="server" Text='<%# Bind("領用帳號") %>' />
<br />
GCIC單號:
<asp:TextBox ID="GCIC單號TextBox" runat="server" Text='<%# Bind("GCIC單號") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="更新" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="取消" />
</EditItemTemplate>
<InsertItemTemplate>
姓名:
<asp:TextBox ID="姓名TextBox" runat="server" Text='<%# Bind("姓名") %>' />
<br />
RM日期:
<asp:TextBox ID="RM日期TextBox" runat="server" Text='<%# Bind("RM日期") %>' />
<br />
領用帳號:
<asp:TextBox ID="領用帳號TextBox" runat="server" Text='<%# Bind("領用帳號") %>' />
<br />
GCIC單號:
<asp:TextBox ID="GCIC單號TextBox" runat="server" Text='<%# Bind("GCIC單號") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="插入" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="取消" />
</InsertItemTemplate>
<ItemTemplate>
識別碼:
<asp:Label ID="識別碼Label" runat="server" Text='<%# Eval("識別碼") %>' />
<br />
姓名:
<asp:Label ID="姓名Label" runat="server" Text='<%# Bind("姓名") %>' />
<br />
RM日期:
<asp:Label ID="RM日期Label" runat="server" Text='<%# Bind("RM日期") %>' />
<br />
領用帳號:
<asp:Label ID="領用帳號Label" runat="server" Text='<%# Bind("領用帳號") %>' />
<br />
GCIC單號:
<asp:Label ID="GCIC單號Label" runat="server" Text='<%# Bind("GCIC單號") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="編輯" />
&nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="刪除" />
&nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="新增" />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString6 %>" DeleteCommand="DELETE FROM [samsung RM] WHERE [識別碼] = ? AND (([姓名] = ?) OR ([姓名] IS NULL AND ? IS NULL)) AND (([RM日期] = ?) OR ([RM日期] IS NULL AND ? IS NULL)) AND (([領用帳號] = ?) OR ([領用帳號] IS NULL AND ? IS NULL)) AND (([GCIC單號] = ?) OR ([GCIC單號] IS NULL AND ? IS NULL))" InsertCommand="INSERT INTO [samsung RM] ([識別碼], [姓名], [RM日期], [領用帳號], [GCIC單號]) VALUES (?, ?, ?, ?, ?)" OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:ConnectionString6.ProviderName %>" SelectCommand="SELECT * FROM [samsung RM]" UpdateCommand="UPDATE [samsung RM] SET [姓名] = ?, [RM日期] = ?, [領用帳號] = ?, [GCIC單號] = ? WHERE [識別碼] = ? AND (([姓名] = ?) OR ([姓名] IS NULL AND ? IS NULL)) AND (([RM日期] = ?) OR ([RM日期] IS NULL AND ? IS NULL)) AND (([領用帳號] = ?) OR ([領用帳號] IS NULL AND ? IS NULL)) AND (([GCIC單號] = ?) OR ([GCIC單號] IS NULL AND ? IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_識別碼" Type="Int32" />
<asp:Parameter Name="original_姓名" Type="String" />
<asp:Parameter Name="original_姓名" Type="String" />
<asp:Parameter Name="original_RM日期" Type="String" />
<asp:Parameter Name="original_RM日期" Type="String" />
<asp:Parameter Name="original_領用帳號" Type="String" />
<asp:Parameter Name="original_領用帳號" Type="String" />
<asp:Parameter Name="original_GCIC單號" Type="String" />
<asp:Parameter Name="original_GCIC單號" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="識別碼" Type="Int32" />
<asp:Parameter Name="姓名" Type="String" />
<asp:Parameter Name="RM日期" Type="String" />
<asp:Parameter Name="領用帳號" Type="String" />
<asp:Parameter Name="GCIC單號" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="姓名" Type="String" />
<asp:Parameter Name="RM日期" Type="String" />
<asp:Parameter Name="領用帳號" Type="String" />
<asp:Parameter Name="GCIC單號" Type="String" />
<asp:Parameter Name="original_識別碼" Type="Int32" />
<asp:Parameter Name="original_姓名" Type="String" />
<asp:Parameter Name="original_姓名" Type="String" />
<asp:Parameter Name="original_RM日期" Type="String" />
<asp:Parameter Name="original_RM日期" Type="String" />
<asp:Parameter Name="original_領用帳號" Type="String" />
<asp:Parameter Name="original_領用帳號" Type="String" />
<asp:Parameter Name="original_GCIC單號" Type="String" />
<asp:Parameter Name="original_GCIC單號" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>



搜尋相關Tags的文章: [ DetailsView新增的問題 ] ,
本篇文章發表於2017-11-18 23:23
1樓
回應

P陳
檢舉此回應
這已經是白話文了, 你要我們如何協助你。

您嘗試指定 Null 值給一個不是 Variant 資料類型的變數。

檢查一下,這其中的某個欄位沒有給值。

ConnectionString="<%$ ConnectionStrings:ConnectionString6 %>" DeleteCommand="DELETE FROM [samsung RM] WHERE [識別碼] = ? AND (([姓名] = ?) OR ([姓名] IS NULL AND ? IS NULL)) AND (([RM日期] = ?) OR ([RM日期] IS NULL AND ? IS NULL)) AND (([領用帳號] = ?) OR ([領用帳號] IS NULL AND ? IS NULL)) AND (([GCIC單號] = ?) OR ([GCIC單號] IS NULL AND ? IS NULL))" InsertCommand="INSERT INTO [samsung RM] ([識別碼], [姓名], [RM日期], [領用帳號], [GCIC單號]) VALUES (?, ?, ?, ?, ?)" OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:ConnectionString6.ProviderName %>" SelectCommand="SELECT * FROM [samsung RM]" UpdateCommand="UPDATE [samsung RM] SET [姓名] = ?, [RM日期] = ?, [領用帳號] = ?, [GCIC單號] = ? WHERE [識別碼] = ? AND (([姓名] = ?) OR ([姓名] IS NULL AND ? IS NULL)) AND (([RM日期] = ?) OR ([RM日期] IS NULL AND ? IS NULL)) AND (([領用帳號] = ?) OR ([領用帳號] IS NULL AND ? IS NULL)) AND (([GCIC單號] = ?) OR ([GCIC單號] IS NULL AND ? IS NULL))">
本篇文章回覆於2017-11-19 09:21
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
最有價值解答

topcat
捐贈 VP 給 topcat 檢舉此回應
您嘗試指定 Null 值給一個不是 Variant 資料類型的變數。

講白話,應該有值的欄位,卻沒有給值
所以,在執行資料庫維護之前,要檢查必須有值的欄位是否有值,如果沒有,應該給個預設值

這些,該動手寫程式囉∼

樓主打算用c#還是vb.net撰寫?
本篇文章回覆於2017-11-19 10:50
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.