Hello expert, I had a problem in C# datagridview. I want display last month data or ?days only when form load.
I know use SQL query. But the problem is at datetime and string. my idea is today date - 30 days.
private void OT_Load(object sender, EventArgs e)
{
ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string name = conSettings.ProviderName;
string providerName = conSettings.ProviderName;
string ConnectionString = conSettings.ConnectionString;
string sql = "SELECT * FROM OT ORDER BY OTDate";
OleDbConnection connection = new OleDbConnection(ConnectionString);
connection.Open();
sCommand = new OleDbCommand(sql, connection);
sAdapter = new OleDbDataAdapter(sCommand);
sBuilder = new OleDbCommandBuilder(sAdapter);
sDs = new DataSet();
sAdapter.Fill(sDs, "OT");
sTable = sDs.Tables["OT"];
connection.Close();
dataGridView1.DataSource = sDs.Tables["OT"];
dataGridView1.ReadOnly = true;
save_btn.Enabled = false;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dtpDate.Value = System.DateTime.Today;
timerName.Enabled = true;
}