private void btnupdate_Click(object sender, EventArgs e)
{
SqlConnection connection = DBConnectivity.getConnection();
try
{
string query = "UPDATE Student SET RegNo ='" + txtRegNo.Text + "',StudName='" + txtStudentName.Text + "',DateAdd='" + DateTime.Now + "',DOB='" + DateTime.Now + "',Age='" + txtAge.Text + "',Gender='" + cBGender.Text + "',PrAddress='" + txtAddress.Text + "',PeAddress='" + txtPaddress.Text + "',FName='" + txtFName.Text + "',FMobile='" + mtxtFmobile.Text + "',FOccupation='" + txtFOccupation.Text + "',MName='" + txtMName.Text + "',MOccupation='" + txtMOccupation.Text + "',Nationality= '" + ComboBox3.Text + "',Area='" + ComboBox1.Text + "',BPlace='" + TextBox12.Text + "',Religion='" + TextBox13.Text + "',AdmitedTo='" + cBClass.Text + "' ,RollNo ='" + txtRollNo.Text + "',CNIC='" + mtxtCNIC.Text + "',Mobile='" + mtxtMobileStud.Text + "' where id='" + txtid.Text + "'";
SqlCommand command = DBConnectivity.getCommandForQuery(query, connection);
int result1 = command.ExecuteNonQuery();
if (pho == 1)
{
string query2 = " Update Photo SET PID='"+pho+"', SID='"+txtRegNo.Text+"', SName='"+txtStudentName.Text+"', StudImage='"+Photos1+"' Where id='"+txtid.Text+"' ";
Photos1 = System.IO.File.ReadAllBytes(OpenFileDialog1.FileName);
SqlCommand command2 = DBConnectivity.getCommandForQuery(query2, connection);
int result2 = command2.ExecuteNonQuery();
}
}
catch (Exception ex)
{ }
}
This is the table of data, but the table with the student is updated, but the photo is not there.
1条答案
按热度按时间gcmastyq1#
Just combine them into the same SQL batch, checking to see if the
photo
has been passed in or is null.DbNull.Value
if you don't have a value.using
to dispose the connection and command.async
to make your UI more responsive.It;s not entirely clear if the
Photo
actually needs to be inserted. If so, do