Hi
You can Use from bellow method for manage Database:
public class DBManagement
{
public SqlConnection OpenConnection()
{
string connectionString = "Data Source = [ServerName]; Initial Catalog = [DatabaseName]; User ID = [SqlUserName]; Password = [SqlUserPassword]";
SqlConnection connection = null;
try
{
connection = new SqlConnection(connectionString);
connection.Open();
}
catch
{
Console.WriteLine("DataBase is not reachable....");
}
return connection;
}
public DataTable Execute(string queryString)
{
SqlConnection connection = OpenConnection();
SqlCommand query = new SqlCommand(queryString, connection);
DataTable resultTable = new DataTable();
SqlDataAdapter adopter = new SqlDataAdapter(query);
adopter.Fill(resultTable);
connection.Close();
return resultTable;
}
}
Now you can create instance from DBManagement and call execute method by send bellow string az query:
string query = "Select Name From YourTableName Where Age = 25";
DBManagement manage = new DBManagement();
DataTable result = manage.Execute(query);
I hope it's helpful.