i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why can I save the error information into the table of SQL server ?
09-29-2015, 04:36 AM
Post: #1
Why can I save the error information into the table of SQL server ?
Why I can not save the error information in the table: TABERRORINFO. Suppose I have two: TABCUSTOMER and TABERRORINFO.

Code:
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)
        {
            ClsConnection.objConnect.Close();
            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);
            try
            {
                cmd.Parameters.AddWithValue("@NgayErr", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                cmd.Parameters.AddWithValue("@MesaErr", MessErr);
                cmd.Parameters.AddWithValue("@SQLErr", SqlErr);
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                objConnect.Close();
                DevExpress.XtraEditors.XtraMessageBox.Show("Saved" + MessErr);
            }
            catch (SqlException ex)
            {                
                objConnect.Close();
                //MessageBox.Show("SaveMessageErrSQL lỗi: " + sSQL);
                MessageBox.Show("No Save Message Errer into SQL: " + ex.Message);
            }

        }



Quote


Possibly Related Threads...
Thread: Author Replies Views: Last Post
  Can save directly from the DataTable into the Table of Access 2000 ? dongtrien 0 582 10-31-2016 01:55 AM
Last Post: dongtrien
  Save DataTable to database c# nisar87 3 5,243 01-27-2013 07:03 PM
Last Post: nisar87
  Getting list of databases from a sql server c# haider.ali 0 6,316 12-06-2011 06:53 PM
Last Post: haider.ali
  Sql server Database restore using c# haider.ali 0 7,002 08-23-2011 04:52 PM
Last Post: haider.ali
  Sql server Database backup using c# haider.ali 0 4,571 08-18-2011 04:39 PM
Last Post: haider.ali



User(s) browsing this thread: 1 Guest(s)