Dasran Rajlui Dasran Rajlui - 6 months ago 19
SQL Question

no mapping exists from object type

private void button5_Click(object sender, EventArgs e)
{


DataGridViewRow updatedrow = dataGridView1.Rows[chooseAnyRow];

updatedrow.Cells[0].Value = SALUTATION.Text;
updatedrow.Cells[1].Value = NAME.Text;
updatedrow.Cells[2].Value = SEX.Text;
updatedrow.Cells[3].Value = ETHNICITY.Text;
updatedrow.Cells[4].Value = MARITALSTATUS.Text;
updatedrow.Cells[5].Value = ICNUMBER.Text;
updatedrow.Cells[6].Value = HPNUMBER.Text;
updatedrow.Cells[7].Value = DOB.Text;
updatedrow.Cells[8].Value = ADDRESS.Text;
updatedrow.Cells[9].Value = STATE.Text;
updatedrow.Cells[10].Value = CITY.Text;
updatedrow.Cells[11].Value = POSTCODE.Text;
updatedrow.Cells[12].Value = pictureBox1.Image;




con = new SqlConnection(@"Data Source=dasranrajlui\sqlexpress;Initial Catalog=SESoriginal;Integrated Security=True");
con.Open();
com = con.CreateCommand();
com.CommandType = CommandType.Text;
com.CommandText = " update VoterRegistration set SALUTATION = '" + SALUTATION.Text +
"', NAME = '" + NAME.Text +
"', SEX = '" + SEX.Text +
"', ETHNICITY = '" + ETHNICITY.Text +
"', MARITALSTATUS = '" + MARITALSTATUS.Text +
"', IC_NUMBER = " + ICNUMBER.Text +
", HP_NUMBER = " + HPNUMBER.Text +
", DOB = '" + DOB.Text +
"', ADDRESS = '" + ADDRESS.Text +
"', STATE = '" + STATE.Text +
"', CITY = '" + CITY.Text +
"', POSTCODE = '" + POSTCODE.Text +
"', VOTER_PIC = @VOTER_PIC where IC_NUMBER = " + ICNUMBER.Text;


com.CommandType = CommandType.Text;
com.Parameters.AddWithValue("@VOTER_PIC", pictureBox1.Image);
com.Parameters.AddWithValue("@Salutation", SALUTATION.Text);
com.Parameters.AddWithValue("@Name", NAME.Text);
com.Parameters.AddWithValue("@Sex", SEX.Text);
com.Parameters.AddWithValue("@Ethnicity", ETHNICITY.Text);
com.Parameters.AddWithValue("@MaritalStatus", MARITALSTATUS.Text);
com.Parameters.AddWithValue("@ICNumber", ICNUMBER.Text);
com.Parameters.AddWithValue("@HPNumber", HPNUMBER.Text);
com.Parameters.AddWithValue("@Dob", DOB.Text);
com.Parameters.AddWithValue("@Address", ADDRESS.Text);
com.Parameters.AddWithValue("@State", STATE.Text);
com.Parameters.AddWithValue("@City", CITY.Text);
com.Parameters.AddWithValue("@PostCode", POSTCODE.Text);

if (pictureBox1.Image != null)
{

ms = new MemoryStream();
pictureBox1.Image.Save(ms, ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
com.Parameters.AddWithValue("@VOTER_PIC", photo_aray);
}

try
{
com.ExecuteNonQuery();
MessageBox.Show("updated...");

SALUTATION.Text = null;
NAME.Text = null;
SEX.Text = null;
ETHNICITY.Text = null;
MARITALSTATUS.Text = null;
ICNUMBER.Text = null;
HPNUMBER.Text = null;
DOB.Text = null;
ADDRESS.Text = null;
STATE.Text = null;
CITY.Text = null;
POSTCODE.Text = null;

}

catch (Exception EX)
{
MessageBox.Show(EX + "NOT Updated");
}

finally
{
con.Close();
}

}


The error shows : no mapping exists from object type
is it because my convert image is wrong?
or it there is other way to update the image to my sql?
The thing is i need to update my values n the image which i can display and update which can save to my database.

Answer

I suggest that you remove the , before where and add a quote around ICNUMBER.text

  "', POSTCODE = '" + POSTCODE.Text + "' where IC_NUMBER = '" + ICNUMBER.Text  +"'";
Comments