Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>the most viable to date option for database work is to use something like entity framework your model is the model, your database connection sits on its own and you can easily port the application to another database provider if need... I.E mysql to msSQL without really having to do much in the way of work.</p> <p>Entity framework code first is the easiest i think to port over. Also for mysql you just need the mysql.net connector from the provider themselves, this works with entity framework.</p> <p>also by working with models and using linq you further help reduce prodlems with SQL injection as you wont actually be writing or sending any SQL.</p> <p>Given that, should you have a massive database, EF is a pain in the butt and is really slow and for this a simple database class would do, you can have a few functions like this:</p> <pre><code>private readonly MySqlConnection _conn = new MySqlConnection(); private MySqlCommand _myCommand = new MySqlCommand(); private readonly string _dbConn = ConfigurationManager.AppSettings["dbConn"]; public void Closedb() { try { _conn.Dispose(); _conn.Close(); } catch (Exception ex) { } } public void UpdateDatabaseWithSql(string mysql) { Closedb(); _conn.ConnectionString = _dbConn; _conn.Open(); _myCommand= new MySqlCommand(mysql,_conn); _myCommand.ExecuteNonQuery(); Closedb(); } </code></pre> <p>a DB connection for mysql looks like this, in the web.config file:</p> <pre><code>&lt;add name="MvcCustomContext" connectionString="server=[ip];User Id=[user];password=[pass];Persist Security Info=True;database=[dbname]" providerName="MySql.Data.MySqlClient" /&gt; </code></pre> <p>hope this helps</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload