Reputation: 155
This sql statement I check and it works:
UPDATE
faxcomplete
SETDATE
= curdate() WHEREDATE
='0000-00-00'
When I run the code it not update database. I am a beginner and I don't know how to check if something is wrong:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string MyConString = "SERVER=localhost;" +
"DATABASE=webboard;" +
"UID=root;" +
"PASSWORD='';";
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "UPDATE `faxcomplete` SET `DATE`= curdate() WHERE `DATE`='0000-00-00'";
}
}
}
Upvotes: 0
Views: 494
Reputation: 6555
Execute the SQL:
command.ExecuteNonQuery();
You also need to close the connection once you're done.
connection.Close();
You do not need the line
MySqlDataReader Reader;
Upvotes: 3
Reputation: 4187
well one thing i noticed is that your not executing the command or binding it to the connection. I tend to use something like
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand("name", connection))
{
command.CommandText = "UPDATE `faxcomplete` SET `DATE`= curdate() WHERE `DATE`='0000-00-00'";
command.ExecuteNonQuery();
}
}
Upvotes: 1