创建帐户时,无法插入值,并且错误显示作为主键的列( if (tglAkhir.isBefore(tglAwal)) {
System.out.println("Tanggal berada dalam urutan yang salah");
} else {
long bedaHari = ChronoUnit.DAYS.between(tglAwal, tglAkhir);
System.out.println("" + bedaHari + " hari");
}
)不允许为空。因此,PatronID
失败
曾经尝试进入SQL Server表设计器来更改“身份”,但是我无法保存更改
INSERT
在public int add()
{
string strConn = ConfigurationManager.ConnectionStrings["BABAFOODSConnectionString"].ToString();
SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand("INSERT INTO Patron (PatronName, PatronEmail, PatronPassword)" +
"OUTPUT INSERTED.PatronID " +
"VALUES(@name, @email, @password)", conn);
cmd.Parameters.AddWithValue("@name", PatronName);
cmd.Parameters.AddWithValue("@email", PatronEmail);
cmd.Parameters.AddWithValue("@password", PatronPassword);
conn.Open();
int id = (int) cmd.ExecuteScalar();
conn.Close();
return id;
}
,出现此错误:
System.Data.SqlClient.SqlException:'无法将值NULL插入表'BABAFOODS.dbo.Patron'的列'PatronID'中;列不允许为空。 INSERT失败。'