このエラーメッセージが表示されます: 'NULL'という値を 'id'、table ''列に挿入できません。列はNULLを許可しません。 INSERTは失敗します。事前に感謝TextBoxからSQLに値を挿入します
protected void AddItem(object sender, EventArgs e)
{
string insertCmd = "INSERT INTO Picture (Album, id) VALUES (@Album, @id)";
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConn"].ConnectionString))
{
conn.Open();
SqlCommand myCommand = new SqlCommand(insertCmd, conn);
// Create parameters for the SqlCommand object
// initialize with input-form field values
myCommand.Parameters.AddWithValue("@Album", txtAlbum.Text);
myCommand.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
myCommand.ExecuteNonQuery();
int id = (int)myCommand.Parameters["@id"].Value;
}
}
データベースに挿入する前にnull値を空にするだけです – Meena