在表现层使用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"