MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
string myConnectionString;
myConnectionString = "server=localhost;uid=[COLOR="#FF0000"]USERNAME[/COLOR];" +
"pwd=[COLOR="#FF0000"]PASSWORD[/COLOR];database=[COLOR="#FF0000"]DATABASENAME[/COLOR];";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Authors(Name) VALUES(@Name)";
cmd.Prepare();
cmd.Parameters.AddWithValue("@Name", "Trygve Gulbranssen");
cmd.ExecuteNonQuery();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
return(ex.Message);
}
Use C# code for it.
Download the .Net Connector and install. You will need to reference the MySql.Data.dll that it installs in the GAC.
Then to connect, throw this into a C# action....
Код:MySql.Data.MySqlClient.MySqlConnection conn; MySql.Data.MySqlClient.MySqlCommand cmd; string myConnectionString; myConnectionString = "server=localhost;uid=[COLOR="#FF0000"]USERNAME[/COLOR];" + "pwd=[COLOR="#FF0000"]PASSWORD[/COLOR];database=[COLOR="#FF0000"]DATABASENAME[/COLOR];"; try { conn = new MySql.Data.MySqlClient.MySqlConnection(); conn.ConnectionString = myConnectionString; conn.Open(); cmd = new MySql.Data.MySqlClient.MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO Authors(Name) VALUES(@Name)"; cmd.Prepare(); cmd.Parameters.AddWithValue("@Name", "Trygve Gulbranssen"); cmd.ExecuteNonQuery(); } catch (MySql.Data.MySqlClient.MySqlException ex) { return(ex.Message); }
Of course this is an example of inputting a record into the table. Your queries will vary depending on what you need.
I'm using a remote DBDid you remember to turn on your Wampserver? lol. Done it plenty of times.

I using simple php form for connecting my local mysql, without C#, above form i can read or put values .
<html>
<body>
<form action="insert.php" method="post">
Account: <input type="text" name="account">
Status: <input type="text" name="status">
<input type="submit">
</form>
</body>
</html>
<?php
$host = "1.1.1.1";
$user = "root";
$pass = "password";
$database = "db_0001";
$conn = mysql_connect($host, $user, $pass) or die( mysql_error() );
mysql_select_db($database) or die( mysql_error() );
$account = mysql_real_escape_string( $_POST["account"] );
$status = mysql_real_escape_string( $_POST["status"] );
$sql = "UPDATE accounts_table SET status = '{$status}' WHERE account = '{$account}'";
$result = mysql_query( $sql ) or die( mysql_error() );
header("Location: index.html");
?>
Hi,
I want to connect to a database and read/write some data to the tables. How can I connect and read/write data from a database if I am creating a template in Project maker and not code creator?
Thanks