0% found this document useful (0 votes)
24 views10 pages

DocumentationInIntegrativeProgramming Corcino

The document describes steps to create a C# application that inserts user input data into a MySQL database using Visual Studio and XAMPP. It involves installing VS 2022 and XAMPP, creating a project, designing the UI, connecting to a database, adding dependencies, running XAMPP, creating a table, inserting data, and clearing fields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views10 pages

DocumentationInIntegrativeProgramming Corcino

The document describes steps to create a C# application that inserts user input data into a MySQL database using Visual Studio and XAMPP. It involves installing VS 2022 and XAMPP, creating a project, designing the UI, connecting to a database, adding dependencies, running XAMPP, creating a table, inserting data, and clearing fields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Ralph Ryan L Corcino

Adrian Berino

Kleford Edianel

Aaron Alcantara

BSIT 402

1. Install VS 2022 and Xampp server into your Computer

2. Open the VS 2022.


3. Create New Project

4. Create your desired design for the Activity 4


5.After designing, create a connection between your code and the Xampp Database. In my case, I used
my info Database.

6. Create a unique variable for each of your textboxes, checked list group and combo box to call later on.

7. Create a query to insert the info put by the user input into the database and to call the table data into
their separate variables.
8. Create a clear button to clear all the textboxes, checked list group and combo box.8. choose

9. Dependencies in your solution manager and choose Manage NuGet.


10. Open NuGet Manager, Search and Install MySQL.Data and NuGet Framwork.

11. Run Xampp on administrator.


12. Open Xampp Server and start Apache and MySQL and click admin of the MySQL to open the
database.

13. Create a new database. In my case I used my info Database.


14. Create a table where the data will be received coming from the code. In this case I created a new
table name student_demo to store data.

15. after creating a table you will prompt to this setup where all the data will nested in, put in these
necessary columns for these are the table where the information will stay.
16. Run the code to see if there are no errors.

17. fill the necessary data needed.


18. Check if the data was inserted into the database and to see if the program is working well.

Code:
using MySql.Data.MySqlClient;

namespace DatabaseCorcino
{
public partial class Form1 : Form
{
string connectionString = "datasource=localhost;port=3306;user=root;password=;database=info";
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void btnSubmit_Click(object sender, EventArgs e)


{
// Get the input values from the text boxes, combo box, and check boxes
string studentNumber = txtStudentNumber.Text;
string lastName = txtLastName.Text;
string firstName = txtFirstName.Text;
int age = int.Parse(txtAge.Text); // Assumes the age input is a valid integer
string gender = cboGender.Text;

// Concatenate the selected course(s) into a single string with comma separator
string courses = "";
foreach (var course in checkedListBoxCourses.CheckedItems)
{
if (courses != "") courses += ", "; // Add separator if not the first course selected
courses += course.ToString();
}

// Insert the student information into the database


try
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();

// Prepare the SQL statement with parameter placeholders


string query = "INSERT INTO students (student_number, last_name, first_name, age, gender, courses) " +
"VALUES (@student_number, @last_name, @first_name, @age, @gender, @courses)";
using (MySqlCommand command = new MySqlCommand(query, connection))
{
// Add parameters with the input values
command.Parameters.AddWithValue("@student_number", studentNumber);
command.Parameters.AddWithValue("@last_name", lastName);
command.Parameters.AddWithValue("@first_name", firstName);
command.Parameters.AddWithValue("@age", age);
command.Parameters.AddWithValue("@gender", gender);
command.Parameters.AddWithValue("@courses", courses);

// Execute the SQL statement


command.ExecuteNonQuery();

MessageBox.Show("Student information has been successfully submitted.", "Success");


}
}
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}", "Error");
}
}

private void btnClear_Click(object sender, EventArgs e)


{
txtStudentNumber.Clear();
txtLastName.Clear();
txtFirstName.Clear();
txtAge.Clear();
cboGender.Text = "";
for (int i = 0; i < checkedListBoxCourses.Items.Count; i++)
{
checkedListBoxCourses.SetItemChecked(i, false);
}
}
}
}

You might also like