0

我正在使用访问表

我正在使用包含这些公共功能的 oleDBManager:

/// <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;
}

在我的“用户”表中,每个用户都有一个“用户 ID”、“用户名”、“密码”和“登录名”。我的问题是,当用户登录时(我有用户名和密码),我怎样才能得到他的“登录”列的值?如果我可以将它设置为一个 int 会更好(如果重要的话,我已经将“登录”列设置为从“文本”访问“数字”。

编辑:我想做的是更新用户登录的次数。如果有更好的方法,请告诉我。

4

2 回答 2

0

您可以使用返回对象的 ExecuteScalar() 函数, 或者 您可以使用 ExecuteRead() 并将
其存储在这样的字符串中

string logins= dt.rows[0].itemarray[0].tostring()
于 2012-12-08T18:57:23.220 回答
0

回答:

所以,虽然没有人回答我,但我自己已经学会了:

这是代码的全部部分(用户名是用户名,也是一个同名的字符串,登录是列,用户是表)

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 + "'");
于 2012-12-10T13:20:51.430 回答