在表现层使用DetailView的插入数据的时候,输入字符串的格式不正确。
在表现层使用DetailView的插入数据的时候,输入字符串的格式不正确。
我的数据表名称:calMainRecords
数据表结构及其数据类型:
ID char(6) 不容许空
Equipment_Name varchar(50) 容许空
Use_Place_ID int 不容许空
Cal_Date datetime 不容许空
Due_Date datetime 不容许空
Cal_Cycle_ID int 不容许空
Vender varchar(50) 容许空
Brand varchar(50) 容许空
Model varchar(50) 容许空
Serial_NO varchar(50) 容许空
Accuracy varchar(50) 容许空
Class char(1) 不容许空
Project_ID int 不容许空
Process_ID int 不容许空
Status char(1) 不容许空
WI_NO char(12) 不容许空
Drawing_NO char(12) 容许空
Renter_ID int 容许空
Rent_Date datetime 容许空
Sign_ID int 不容许空
Remark varchar(255) 容许空
我的方法: public bool AddcalMainRecords(String equipment_Name, DateTime? cal_Date, DateTime? due_Date, String vender, String brand, String model, String serial_NO, String accuracy, String myclass, String status, String WI_NO, String drawing_NO, String remark, int id)
{
// 新建一个calMainRecordsRow实例
cal.calMainRecordsDataTable mycals = new cal.calMainRecordsDataTable();
cal.calMainRecordsRow mycal = mycals.NewcalMainRecordsRow();
mycal.Equipment_Name = equipment_Name;
if (equipment_Name == null) mycal.SetEquipment_NameNull(); else mycal.Equipment_Name = equipment_Name;
if (vender == null) mycal.SetVenderNull(); else mycal.Vender = vender;
if (brand == null) mycal.SetBrandNull(); else mycal.Brand = brand;
if (model == null) mycal.SetModelNull(); else mycal.Model = model;
if (serial_NO == null) mycal.SetSerial_NONull(); else mycal.Serial_NO = serial_NO;
if (accuracy == null) mycal.SetAccuracyNull(); else mycal.Accuracy = accuracy;
if (drawing_NO == null) mycal.SetDrawing_NONull(); else mycal.Drawing_NO = drawing_NO;
//少了Renter_ID和Rent_Date
if (remark == null) mycal.SetRemarkNull(); else mycal.Remark = remark;
mycals.AddcalMainRecordsRow(mycal);
int rowsAffected = Adapter.Update(mycals);
// 如果刚好新增了一条记录,则返回true,否则返回false
return rowsAffected == 1;
}
表现层前台代码:
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="BasicEdit.aspx.cs" Inherits="Basic_BasicEdit" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:DetailsView ID="DetailsView1" runat="server"
DataSourceID="objGetDatas" Height="50px" Width="125px"
AutoGenerateRows="False" DataKeyNames="ID">
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="Equipment_Name" HeaderText="Equipment_Name"
SortExpression="Equipment_Name" />
<asp:BoundField DataField="Cal_Date" HeaderText="Cal_Date"
SortExpression="Cal_Date" />
<asp:BoundField DataField="Due_Date" HeaderText="Due_Date"
SortExpression="Due_Date" />
<asp:BoundField DataField="Vender" HeaderText="Vender"
SortExpression="Vender" />
<asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Serial_NO" HeaderText="Serial_NO"
SortExpression="Serial_NO" />
<asp:BoundField DataField="Accuracy" HeaderText="Accuracy"
SortExpression="Accuracy" />
<asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
<asp:BoundField DataField="WI_NO" HeaderText="WI_NO" SortExpression="WI_NO" />
<asp:BoundField DataField="Drawing_NO" HeaderText="Drawing_NO"
SortExpression="Drawing_NO" />
<asp:BoundField DataField="Remark" HeaderText="Remark"
SortExpression="Remark" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="objGetDatas" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Equipment_Name" HeaderText="Equipment_Name" SortExpression="Equipment_Name" />
<asp:BoundField DataField="Cal_Date" HeaderText="Cal_Date" SortExpression="Cal_Date" />
<asp:BoundField DataField="Due_Date" HeaderText="Due_Date" SortExpression="Due_Date" />
<asp:BoundField DataField="Vender" HeaderText="Vender" SortExpression="Vender" />
<asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Serial_NO" HeaderText="Serial_NO" SortExpression="Serial_NO" />
<asp:BoundField DataField="Accuracy" HeaderText="Accuracy" SortExpression="Accuracy" />
<asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" />
<asp:BoundField DataField="WI_NO" HeaderText="WI_NO" SortExpression="WI_NO" />
<asp:BoundField DataField="Drawing_NO" HeaderText="Drawing_NO"
SortExpression="Drawing_NO">
</asp:BoundField>
<asp:BoundField DataField="Remark" HeaderText="Remark"
SortExpression="Remark" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="objGetDatas" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetCalDatas" TypeName="calBLL"
InsertMethod="AddcalMainRecords">
<InsertParameters>
<asp:Parameter Name="equipment_Name" Type="String" />
<asp:Parameter Name="cal_Date" Type="DateTime" />
<asp:Parameter Name="due_Date" Type="DateTime" />
<asp:Parameter Name="vender" Type="String" />
<asp:Parameter Name="brand" Type="String" />
<asp:Parameter Name="model" Type="String" />
<asp:Parameter Name="serial_NO" Type="String" />
<asp:Parameter Name="accuracy" Type="String" />
<asp:Parameter Name="myClass" Type="String" />
<asp:Parameter Name="status" Type="String" />
<asp:Parameter Name="WI_NO" Type="String" />
<asp:Parameter Name="drawing_NO" Type="String" />
<asp:Parameter Name="remark" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
</asp:Content>
[解决办法]
楼主,你这帖子好像有点长。虽然看的人多,但是回复的不多。。你要找出问题所在然后在发帖,而不是发出源码让别人帮你找错误。。。呵呵,打酱油的,别介意
[解决办法]
每个参数(类型)都要一一对应上才行。
自己一个个检查。