Hello there.
I've put together an Access Database which handles opening hours.
However I want to be able to update each day individually, but at the moment it updates the entire week in one go.
I know that I'm supposed to add some sort of WHERE in my sql sentence, but I can't wrap my brain around the syntax for it...
Parts of the code is in danish, since my education requires it (stupid I know) let me know if you want me to translate it to english words, so it's easier to get an overview.
The database has two colums. One with the seven days of the week, and one with opening hours.
The class is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.OleDb;
using System.Web.Configuration;
namespace AabningstiderClass
{
/// <summary>
/// Summary description for aabningsTider
/// </summary>
public class aabningsTider
{
private string mandag;
private string tirsdag;
public aabningsTider()
{
//
// TODO: Add constructor logic here
//
}
public string Mandag
{
set { mandag = value; }
get { return mandag; }
}
public string Tirsdag
{
set { tirsdag = value; }
get { return tirsdag; }
}
//Opdater til database
public string OpdaterTid()
{
string strSQL;
strSQL = "UPDATE aabningsTabel SET aabningsTid = '" + this.Mandag.ToString() + "'";
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|aabningstider.mdb";
try
{
myConnection.Open();
OleDbCommand myCommand = new OleDbCommand(strSQL, myConnection);
myCommand.ExecuteNonQuery();
return "Der skete en fejl i opdateringen";
}
catch (Exception ex)
{
string strFejl;
strFejl = "Databasen blev ikke åbnet";
strFejl += ex.ToString();
return strFejl;
}
finally
{
myConnection.Close();
}
}
}
}
And the execution:
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AabningstiderClass;
public partial class aabning2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btGem_Click(object sender, EventArgs e)
{
aabningsTider opdaterTid = new aabningsTider();
opdaterTid.Mandag = tbMandag.Text;
opdaterTid.OpdaterTid();
}
}
I hope you got some pointers :)
Thanks in advance!