Reputation: 1164
I'm using access table
I'm using this oleDBManager that includes these public functions:
/// <summary>
/// Excecutes an SELECT query and returns the data.
/// </summary>
/// <param name="query">the query string</param>
/// <returns>returns an DataTable instance with the recived data from the selection query.</returns>
public DataTable ExcecuteRead(string query) {
this.link.Open();
// ---
this.dataAdapter = new OleDbDataAdapter(query, this.link);
// ---
this.dataTable = new DataTable();
this.dataAdapter.Fill(this.dataTable);
// ---
this.link.Close();
// ---
return this.dataTable;
}
/// <summary>
/// Returns an HTML table code, with all the rows and the values of the results.
/// </summary>
/// <param name="query">the query string</param>
/// <returns>returns an HTML code as a string</returns>
public string ExcecuteTableRead(string query)
{
string output = "<table border=\"1\">";
// ---
this.dataTable = this.ExcecuteRead(query);
// ---
foreach (DataRow row in this.dataTable.Rows)
{
output += "<tr>";
// ---
foreach (object obj in row.ItemArray)
{
output += "<td>" + obj.ToString() + "</td>";
}
// ---
output += "</tr>";
}
// ---
output += "</table>";
// ---
return output;
}
/// <summary>
/// Returns an HTML table code, with all the rows and the values of the results.
/// </summary>
/// <param name="query">the query string</param>
/// <param name="max">the maximum number of rows to show</param>
/// <returns>returns an HTML code as a string</returns>
public string ExcecuteTableRead(string query, int max)
{
int i = 0;
string output = "<table border=\"1\">";
// ---
this.dataTable = this.ExcecuteRead(query);
// ---
foreach (DataRow row in this.dataTable.Rows)
{
if (i < max)
{
output += "<tr>";
// ---
foreach (object obj in row.ItemArray)
{
output += "<td>" + obj.ToString() + "</td>";
}
// ---
output += "</tr>";
}
i++;
}
// ---
output += "</table>";
// ---
return output;
}
In my "users" table, I have a "userid", "username", "password" and "logins" for each user. My question is, when the user logins (I have the username and the password), how can I get the value of his 'logins' column? Would be even better if I could set it into an int (if it matters, I've set the "logins" column in access to 'number' from 'text'.
Edit: what I'm trying to do is to update the number of times the user has logged in. If there's a better way, please tell me.
Upvotes: 0
Views: 1224
Reputation: 1164
answer:
So, although no one answered me, i've managed to learn it myself:
here is the whole part of the code (username is the name of the user and also a string of it with the same name, logins is the column, users is the table)
string logins = db.ExcecuteTableRead("SELECT logins FROM users WHERE username='" + username + "'");
logins = logins.Substring(21, 20);
logins = Regex.Match(logins, @"\d+").Value;
int loginsInt = Int32.Parse(logins) + 1;
int a = db.ExecuteQuery("UPDATE users SET logins='" + loginsInt.ToString() + "' WHERE username='" + username + "'");
Upvotes: 0
Reputation: 2938
you can use ExecuteScalar() function which returns object
OR
you can use ExecuteRead() and
store it in a string like this
string logins= dt.rows[0].itemarray[0].tostring()
Upvotes: 0