이 오류 메시지가 나타납니다. 'NULL'값을 'id', table ''열에 삽입 할 수 없습니다. 열이 널을 허용하지 않습니다. 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