Why I can not save the error information in the table: TABERRORINFO. Suppose I have two: TABCUSTOMER and TABERRORINFO.
private void cmdSave_Click(object sender, EventArgs e)
{
strSQL = "INSERT INTO TABCUSTOMER(IDCUSTOMER, FULLNAME, ADDRESS, IMAGE) " +
"VALUES (@IDCUSTOME, @FULLNAME, @ADDRESS, @ImageData);";
SqlCommand cmd = new SqlCommand(strSQL, ClsConnection.objConnect);
try
cmd.Parameters.AddWithValue("@IDCUSTOMER", txtIDCustomer.Text);
cmd.Parameters.AddWithValue("@FULLNAME", txtFullName.Text);
cmd.Parameters.AddWithValue("@ADDRESS", txtAddress.Text);
//byte[] ImageData = ReadFile(sPath);
cmd.Parameters.Add(new SqlParameter("@ImageData", (object)ImageData));
if (ClsConnection.objConnect.State != System.Data.ConnectionState.Open)
ClsConnection.objConnect.Open();
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
// Close database
ClsConnection.objConnect.Close();
catch (SqlException ex)
string sConError = "Save Messager Customer 1: " + ex.Message;
SaveMessageErrSQL(sConError, strSQL);
private void SaveMessageErrSQL(string MessErr, string SqlErr)
string sSQL = "UPDATE TABERRORINFO SET ";
sSQL = sSQL + " ERRDATE = @NgayErr";
sSQL = sSQL + ", ERRMESSAGE = @MesaErr";
sSQL = sSQL + ", ERRSQL = @SQLErr";
sSQL = sSQL + " WHERE USERNAME = N'" + sUSERNAME + "';";
Debug.Print(sSQL);
SqlCommand cmd = new SqlCommand(sSQL, objConnect);
cmd.Parameters.AddWithValue("@NgayErr", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
cmd.Parameters.AddWithValue("@MesaErr", MessErr);
cmd.Parameters.AddWithValue("@SQLErr", SqlErr);
objConnect.Close();
DevExpress.XtraEditors.XtraMessageBox.Show("Saved" + MessErr);
//MessageBox.Show("SaveMessageErrSQL l?i: " + sSQL);
MessageBox.Show("No Save Message Errer into SQL: " + ex.Message);