【发布时间】:2010-10-28 18:42:22
【问题描述】:
我正在尝试使用三层解决方案(或它可能被称为的)插入到 MySql 数据库。
我已经用 MS-sql 数据库做了很多次,效果很好。
但是现在当我尝试进行插入时,我得到的 ID 不能为空。 我认为数据库可以解决这个问题。 如果我直接在代码中编写插入并使用 MySqlCommand 和 executeNonQuery 效果很好。
MySql 不能使用 BLL 和 DAL 吗?
错误信息:
System.Data.NoNullAllowedException:列“GiftID”不允许空值。在 System.Data.DataColumn.CheckNullable(DataRow row) 在 System.Data.DataColumn.CheckColumnConstraint(DataRow row, DataRowAction action) 在 System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args, DataRow eRow, DataRowAction eAction, Boolean fireEvent) 在 System .Data.DataTable.SetNewRecordWorker(DataRow 行,Int32 提议记录,DataRowAction 操作,布尔 isInMerge,Int32 位置,布尔 fireEvent,Exception& deferredException)在 System.Data.DataTable.InsertRow(DataRow 行,Int32 提议ID,Int32 pos,布尔fireEvent)在System.Data.DataRowCollection.Add(DataRow row) at PayEx.payexusersDataTable.AddpayexusersRow(payexusersRow row) 在 c:\Users\IT\AppData\Local\Temp\Temporary ASP.NET Files\payex\45bd406a\10c84208\App_Code.cyqhjqo7 .1.cs: 第 444 行 PayExBLL.AddPayExUser(String Firstname, String Lastname, String Company, String Address, String Zip, String City, String Phone, String Email, Byte ContactMe, UInt32 Amount, UInt32 TransactionNumber, Byte Anonymous, String Cu rrency) 在 c:\Users\IT\Documents\Visual Studio 2008\WebSites\payex\App_Code\BLL\PayExBLL.cs:第 66 行,位于 c:\Users\IT\Documents 中的 _Default.btn_next3_Click(Object sender, EventArgs e) \Visual Studio 2008\WebSites\payex\Default.aspx.cs:191 行
我的代码:
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
public bool AddPayExUser(string Firstname, string Lastname, string Company, string Address, string Zip, string City, string Phone, string Email, byte ContactMe, uint Amount, uint TransactionNumber, byte Anonymous, string Currency)
{
PayEx.payexusersDataTable puTable = new PayEx.payexusersDataTable();
PayEx.payexusersRow puRow = puTable.NewpayexusersRow();
puRow.Firstname = Firstname;
puRow.Lastname = Lastname;
puRow.Company = Company;
puRow.Address = Address;
puRow.Zip = Zip;
puRow.City = City;
puRow.Phone = Phone;
puRow.Email = Email;
puRow.ContactMe = ContactMe;
puRow.Amount = Amount;
puRow.TransactionNumber = TransactionNumber;
puRow.Anonymous = Anonymous;
puRow.Currency = Currency;
puTable.AddpayexusersRow(puRow);
int rowsAffected = Adapter.Update(puTable);
return rowsAffected == 1;
}
【问题讨论】: