-1
我正在使用兩個單獨的按鈕來旋轉圖像並保存圖像。不知怎的,輪換正在工作。但保存(更新)不起作用。我試圖找到問題,但我不能。值不能爲空。參數名稱編碼器MySql C#
錯誤是「值不能爲空。參數名稱編碼器」。 我最好的猜測是RotateFlip是以某種方式影響圖片框。
問候
這是我的代碼,
private void btnRotate_Click(object sender, EventArgs e)
{
if (pictureBoxProfile.Image != null)
{
pictureBoxProfile.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
pictureBoxProfile.Refresh();
}
else
{
MessageBox.Show("Select an Image");
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (txtShortName.Text == "" || txtPhoneNumberM.Text == "" || txtFullName.Text == "" || gender.Text == "" || richTextBoxAddress.Text == "" || txtPhoneNumberH.Text == "" || status.Text == "" || pictureBoxProfile.Image == null)
{
MessageBox.Show("Empty fields are detected!. Please fill up all fields");
return;
}
try
{
con.Open();
MySqlCommand cmd2 = new MySqlCommand("UPDATE customer SET mr_mrs = @mr_mrs, short_name = @short_name, full_name = @full_name, nic_number = @nic_number, gender = @gender, address = @address, phone_no_home = @phone_no_home, phone_no_mobile = @phone_no_mobile, image = @image, status = @status, type = @type, nic_frnt = @nic_frnt, nic_back = @nic_back WHERE ([email protected]_number)", con);
MemoryStream ms = new MemoryStream();
pictureBoxProfile.Image.Save(ms, pictureBoxProfile.Image.RawFormat);
byte[] img = ms.ToArray();
MemoryStream ms2 = new MemoryStream();
pictureBox1.Image.Save(ms2, pictureBox1.Image.RawFormat);
byte[] img2 = ms2.ToArray();
MemoryStream ms3 = new MemoryStream();
pictureBox3.Image.Save(ms3, pictureBox3.Image.RawFormat);
byte[] img3 = ms3.ToArray();
cmd2.Parameters.AddWithValue("@mr_mrs", mr_mrs.Text);
cmd2.Parameters.AddWithValue("@short_name", txtShortName.Text);
cmd2.Parameters.AddWithValue("@full_name", txtFullName.Text);
cmd2.Parameters.AddWithValue("@nic_number", textBox1.Text);
cmd2.Parameters.AddWithValue("@gender", gender.Text);
cmd2.Parameters.AddWithValue("@address", richTextBoxAddress.Text);
cmd2.Parameters.AddWithValue("@phone_no_home", txtPhoneNumberH.Text);
cmd2.Parameters.AddWithValue("@phone_no_mobile", txtPhoneNumberM.Text);
cmd2.Parameters.AddWithValue("@status", status.Text);
cmd2.Parameters.AddWithValue("@image", img);
cmd2.Parameters.AddWithValue("@type", comboBox1.Text);
cmd2.Parameters.AddWithValue("@nic_frnt", img2);
cmd2.Parameters.AddWithValue("@nic_back", img3);
cmd2.ExecuteNonQuery();
MessageBox.Show(this, "Customer updated succesfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
con.Close();
ClearData();
}
catch (MySqlException x)
{
MessageBox.Show(x.Message);
con.Close();
}
}
我猜你的一列設置爲'不NULL',但你嘗試將它升級到'NULL' – Psi
你在MySQL數據庫的意思? –
是的,這就是我懷疑的 – Psi