错误(空路径名称不合法错误)

时间:2016-04-21 19:45:16

标签: c#

我真的遇到了一个我试图解决的错误,但我无法弄清楚这个问题。我正在尝试的是更新数据库中的记录,我在标题中收到上述错误。

请帮帮我。

提前谢谢。

这是我的代码,这是我收到错误imgData = File.ReadAllBytes(txtImagePath.Text);

的地方
private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                // DB Connection
                SqlConnection con = new SqlConnection(CoonectionString);
                SqlCommand cmd = new SqlCommand("Candidates.SP_Update", con);
                cmd.CommandType = CommandType.StoredProcedure;

                // Declare byte in array which holds image data
                byte[] imgData;
                //imgData = File.ReadAllBytes(EmployeePicture.ImageLocation);
                imgData = File.ReadAllBytes(txtImagePath.Text);

                // Adding data into the DB
                cmd.Parameters.AddWithValue("@CandidateID", SqlDbType.Int).Value = txtCandidateID.Text.Trim();
                cmd.Parameters.AddWithValue("@CandidateStatus", SqlDbType.VarChar).Value = cmbStatus.Text.Trim();
                cmd.Parameters.AddWithValue("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text.Trim();
                cmd.Parameters.AddWithValue("@LastName", SqlDbType.VarChar).Value = txtLastName.Text.Trim();
                cmd.Parameters.AddWithValue("@AddressLine1", SqlDbType.VarChar).Value = txtAddressLine1.Text.Trim();
                cmd.Parameters.AddWithValue("@AddressLine2", SqlDbType.VarChar).Value = txtAddressLine2.Text.Trim();
                cmd.Parameters.AddWithValue("@City", SqlDbType.VarChar).Value = txtCity.Text.Trim();
                cmd.Parameters.AddWithValue("@Telephone", SqlDbType.VarChar).Value = txtTelephone.Text.Trim();
                cmd.Parameters.AddWithValue("@Email", SqlDbType.VarChar).Value = txtEmail.Text.Trim();

                cmd.Parameters.AddWithValue("@Photos", SqlDbType.Image).Value = imgData;

                // Open DB Connection and Execute non query then close DB connection
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();

                // Display message for saved record
                MessageBox.Show("The information has been recorded into the database!", "Saved");
                this.Close();
            }
            catch (Exception ex)
            {
                // Display message for an exception error
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.ToString());
            }
        }

0 个答案:

没有答案