[go: up one dir, main page]

0% found this document useful (0 votes)
3 views2 pages

New Text Document

The document is a C# program that facilitates database operations for managing student information in a college database. It allows users to list, add, update, and delete student records through a console interface. The program utilizes a MySQL database connection and provides options for various operations in a loop until the user decides to exit.

Uploaded by

jk5337362
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

New Text Document

The document is a C# program that facilitates database operations for managing student information in a college database. It allows users to list, add, update, and delete student records through a console interface. The program utilizes a MySQL database connection and provides options for various operations in a loop until the user decides to exit.

Uploaded by

jk5337362
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySqlDBOperations;

namespace DataBaseOperations
{
internal class MainOperations
{
static MySqlDBOperations.Helper objTwo;
static void Main(string[] args)
{
Console.WriteLine("Welcome to Database Operations");

MainOperations objOne = new MainOperations();


string connectionString = "Server=localhost;Database=college;User
ID=root;Password=admin;";
objTwo = new MySqlDBOperations.Helper(connectionString);
//objTwo.OpenConnection();

do
{
Console.WriteLine("Please select an option to perform");
Console.WriteLine("1.List Students data");
Console.WriteLine("2. Add Student Info");
Console.WriteLine("3. Update Student Info");
Console.WriteLine("4. Delete Student Record");
Console.WriteLine("5. Exit");
int iOption = Convert.ToInt32(Console.ReadLine());

switch (iOption)
{
case 1:

objOne.ListData();
break;
case 2:

objOne.AddInfo();

break;
case 3:

objOne.UpdateInfo();
break;
case 4:

objOne.DeleteRecord();
break;
case 5:
objTwo.CloseConnection();

return;
}

} while (true);
}

public void ListData()


{

var dt = objTwo.ExecuteSelectQuery("SELECT
studentId,FirstName,LastName,Age,Gender FROM studentinfo");

foreach (DataColumn column in dt.Columns)


{
Console.Write($"{column.ColumnName}\t");
}
Console.WriteLine();

foreach (DataRow row in dt.Rows)


{
foreach (var item in row.ItemArray)
{
Console.Write($"{item}\t");
}
Console.WriteLine();
}

public void AddInfo()


{

string stringOne = Console.ReadLine();


objTwo.ExecuteSelectQuery(stringOne);

}
public void UpdateInfo()
{

string stringTwo = Console.ReadLine();


objTwo.ExecuteSelectQuery(stringTwo);

}
public void DeleteRecord()
{
string stringThree = Console.ReadLine();
objTwo.ExecuteSelectQuery(stringThree);

}
}

You might also like