U¿ytkownik "ALI-R said:
I have a table of alerts which has a column called "Viewed"(default is 0
which means ,row hasn't been viewed) ,I want to show alerts for an
specific
user and then update "viewed" column to 1 (which means that alert has been
viewed).
thanks for your help.
Ali-R
If you use SQL Server you can do it, for example:
class Class1
{
[STAThread]
static void Main(string[] args)
{
Test t = new Test();
t.MakeTable();
t.ReadAndUpdate();
System.Console.ReadLine();
}
class Test
{
SqlConnection con = new SqlConnection(
"Persist Security Info=False;Integrated Security=SSPI;" +
"database=Testy;server=(local");
public void MakeTable()
{
con.Open();
string sql =
"Create Table myTest(" +
"Id Int Identity(1,1)," +
"Name VarChar(30)," +
"LastRead SmallDateTime);" +
//insert one record to the table
"Insert Into myTest (Name, LastRead) Values('Ben', GetDate())";
SqlCommand myC = new SqlCommand(sql, con);
try
{
myC.ExecuteNonQuery();
}
catch(SqlException ex)
{
System.Console.WriteLine(ex.Message);
}
con.Close();
}
public void ReadAndUpdate()
{
con.Open();
string sql =
"Select * From myTest;" +
//update records in table
"Update myTest Set LastRead = GetDate()";
SqlCommand myC = new SqlCommand(sql, con);
SqlDataReader myRead = myC.ExecuteReader();
myRead.Read();
System.Console.WriteLine("Id={0}, Name={1}, " +
"Last read date time={2}",
myRead.GetInt32(0).ToString(),
myRead.GetString(1),
myRead.GetDateTime(2).ToLongTimeString());
myRead.Close();
con.Close();
}
}
}
In Access db you must use additional update command.
Regards,
Grzegorz