無法將NULL值插入到'AccountID'列中,表'e-BusPassManagementSystem.dbo.TBLAccount';列在這裏不允許空值。 INSERT失敗。 該聲明已被終止。無法將NULL值插入'AccountID'列中,表TBLAccount'列不允許爲空值。 INSERT失敗。該聲明已被終止
我的SQL語句是:
ALTER PROCEDURE SetApplicationForm
@UserID int,
@InstitueName varchar(50),
@ResidentalAddress varchar(max),
@Place varchar(max),
@WorkingDays int,
@Time int,
@Photo varchar(50),
@IDProof varchar(50),
@AppliedDate datetime,
@ValiedUpTo datetime,
@CardType varchar(10),
@Cardno varchar(50),
@CardExpDate datetime
AS
begin
insert into TBLApplicationForm(UserID, InstitueName, ResidentalAddress,
Place, WorkingDays, [Time], Photo,
IDProof, AppliedDate, ValidUpTo, Status)
values(@UserID, @InstitueName, @ResidentalAddress,
@Place, @WorkingDays, @Time, @Photo,
@IDProof, @AppliedDate, @ValiedUpTo, 'PENDING')
declare @ApplicationID int
set @ApplicationID = Scope_Identity()
insert into TBLAccount(UserID, ApplicationID, CardType, CardNumber, Amount, CardExpireDate, Status)
values(@UserID, @ApplicationID, @CardType, @Cardno, '200', @CardExpDate, 'PAID')
end
C#方法:
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
ApplicationFormEntity objAppFrm = new ApplicationFormEntity();
objAppFrm.Institute = txtInstituteName.Text;
objAppFrm.UserID = Convert.ToInt32(Session["UserID"]);
// strName = Convert.ToInt32(txtName.Text).ToString();
objAppFrm.ResidentalAddress = txtResAddr.Text;
objAppFrm.Place = txtPlace.Text;
objAppFrm.WorkingDays = Convert.ToInt32(txtNOD.Text);
objAppFrm.Time = Convert.ToInt32(txtTime.Text);
string strPhoto = Path.GetFileName(fpPhoto.PostedFile.FileName);
fpPhoto.SaveAs(Server.MapPath("Images/" + strPhoto));
// fileuploadimages.SaveAs(Server.MapPath("~/" + filename));
objAppFrm.ProofID = Path.GetFileName(fpIDProof.PostedFile.FileName);
fpPhoto.SaveAs(Server.MapPath("File/" + objAppFrm.ProofID));
objAppFrm.AppliedDate = System.DateTime.Now;
objAppFrm.ValidUpTo = System.DateTime.Now;
objAppFrm.CardType = ddlCardType.Text;
objAppFrm.Cardno = txtCardNumber.Text;
objAppFrm.CardExpDate =DateTime.Parse(txtCardED.Text);
bool blResult = BusinessLayer.ApplicationFormBL.SetApplicationForm(objAppFrm,strPhoto);
if (blResult)
{
lblMsg.Text = "Application applied successfully";
}
else
{
lblMsg.Text = "Not Applied";
ClearApplicationForm();
}
}
catch (Exception ex)
{
throw ex;
}
}
public class ApplicationFormDB
{
public static bool SetApplicationForm(ApplicationFormEntity objAppFrm,string strPhoto)
{
try
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SetApplicationForm";
cmd.Parameters.AddWithValue("@UserID",objAppFrm.UserID);
cmd.Parameters.AddWithValue("@InstitueName", objAppFrm.Institute);
cmd.Parameters.AddWithValue("@ResidentalAddress",objAppFrm.ResidentalAddress);
cmd.Parameters.AddWithValue("@Place",objAppFrm.Place);
cmd.Parameters.AddWithValue("@WorkingDays",objAppFrm.WorkingDays);
cmd.Parameters.AddWithValue("@Time",objAppFrm.Time);
cmd.Parameters.AddWithValue("@Photo",strPhoto);
cmd.Parameters.AddWithValue("@IDProof",objAppFrm.ProofID);
cmd.Parameters.AddWithValue("@AppliedDate",objAppFrm.AppliedDate);
cmd.Parameters.AddWithValue("@ValiedUpTo",objAppFrm.ValidUpTo);
cmd.Parameters.AddWithValue("@CardType", objAppFrm.CardType);
cmd.Parameters.AddWithValue("@Cardno", objAppFrm.Cardno);
cmd.Parameters.AddWithValue("@CardExpDate", objAppFrm.CardExpDate);
int intResullt=DBLayer.ExecuteNonQuery(cmd);
if(intResullt>0)
return true;
else
return false;
}
catch(Exception ex)
{
throw ex;
}
}
我找不到'AccountID'頁面,比錯誤以外的其他任何地方,這意味着你缺少的是在'INSERT'聲明。它是一個身份類型字段?自動號碼? – Habib
錯誤和一些代碼不是問題。 – asawyer