Exemplo n.º 1
0
    /*****
     * Purpose: Save textbox info as a record.
     *
     * Parameter list:
     *  object sender   control that caused the event
     *  EventArgs e     details about the sender
     *
     * Return value:
     *  void
     ******/
    private void btnSave_Click(object sender, EventArgs e)
    {
        int    status;
        int    flag;
        int    i;
        string sqlCommand;

        string[] colNames = new string[MAXCOLUMNS];

        clsDB myDB = new clsDB(dbName);

        myDB.GetColumnInfo(colNames, dbTableName);

        if (chkStatus.Checked == true)
        {
            status = 1;
        }
        else
        {
            status = 0;
        }

        // Build INSERT command
        sqlCommand = "INSERT INTO " + dbTableName + " (";
        for (i = 1; i < colNames.Length; i++)
        {
            if (colNames[i] == null)
            {
                break;
            }
            sqlCommand += colNames[i] + ",";
        }
        i          = sqlCommand.LastIndexOf(',');
        sqlCommand = sqlCommand.Substring(0, i) + ") VALUES ('";
        // Now add the values
        sqlCommand += txtFirstName.Text + "','" +
                      txtMI.Text + "','" +
                      txtLastName.Text + "','" +
                      txtAddr1.Text + "','" +
                      txtAddr2.Text + "','" +
                      txtCity.Text + "','" +
                      txtState.Text + "','" +
                      txtZip.Text + "','" +
                      txtHome.Text + "','" +
                      txtCell.Text + "','" +
                      txtWork.Text + "','" +
                      txtEmail.Text + "','" +
                      txtBirthday.Text + "','" +
                      txtAnniversary.Text + "'," +
                      status.ToString() + ")";

        flag = myDB.ProcessCommand(sqlCommand);
        if (flag == 1)
        {
            MessageBox.Show("Record added successfully.");
        }
        else
        {
            MessageBox.Show("Failed to add data.", "Process Error");
        }
    }