You can do this in c#.net itself like this
Firstly you will have download the MYSQL library which can be found through the nugget packages.
2. Get the MySQL db information e.g. username, password, host etc. and any other info required. Then make something like this which will allow you to connect to the server
Here is an example:
MySqlConnection makeConnection()
{
try
{
server = "localhost";
database = "dbname";
uid = "user";
dbPassword = "password";
string connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + dbPassword + ";";
connection = new MySqlConnection();
connection.ConnectionString = connectionString;
connection.Open();
return connection;
}
catch (MySqlException e)
{
MessageBox.Show(@"Something has gone wrong here (Your own message here if you want)");
Console.WriteLine(e.ToString());
return connection;
}
}
3. You will need to check if the data is on the database.
How do you do it?
Loop through each value and check if it is in the database.
Here is an example:
MySqlConnection conn = makeConnection();
string[] values = new string[] { "string1", "string2", "string3", "string4", "string5", };
for (int i = 0; i < values.Length; i++)
{
string checkQuery = "SELECT col1 FROM table1 WHERE col1 = '" + values[i] + "'";
MySqlCommand checkCommand = new MySqlCommand(checkQuery, conn);
string checkValue = checkCommand.ExecuteScalar().ToString();
if(checkValue == values[i])
{
string updateColumnQuery = "UPDATE table1 SET col2 = 'already here'";
MySqlCommand updateColumnCommand = new MySqlCommand(updateColumnQuery, conn);
updateColumnCommand.ExecuteNonQuery();
}
else
{
string insertColumnQuery = "INSERT INTO table1 (col1) VALUES('"
+ values[i] +"')";
MySqlCommand insertColumnCommand = new MySqlCommand(insertColumnQuery, conn);
insertColumnCommand.ExecuteNonQuery();
}
}
Hope this helps, I haven't tried the code myself but as per my suggestion I think that this code should work. Just remember to get the correct db information otherwise it could be giving lots of errors. That happened to me the first time I was using the MySQL c# library. Hope your final work gets completed.
Rohit Pai, C#, HTML, CSS, JS, PHP, (Python still incomplete)