我应该如何为函数,变量名atrName正确编写变量

时间:2012-02-22 12:44:08

标签: c# asp.net sql database

我想从数据库表中更新1个字段。如您所见,我正在尝试将值vrednost分配给atrName。我的错误发生在这一行:R.+atrName+=如何正确写入该行?

public bool UpdatePlayerVV(string ime, string atrName, string vrednost)
{
    DataSet1.PlayersDataTable his = Adapter.GetDatapl2(ime);
    if (his.Count == 0)
    {
        return false;
    }

    DataSet1.PlayersRow R = his[0];

    if (vrednost == null) { }
    else R.+atrName+= vrednost; 




    int rowsAffected = Adapter.Update(R);


    return rowsAffected == 1;
}

3 个答案:

答案 0 :(得分:0)

var nw = ConfigurationManager.ConnectionStrings["CONNECTION_STRING"];
int count = 0;
using (var connection = new SqlConnection())
{
connection.ConnectionString = nw.ConnectionString;
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update Players set...."
connection.Open();
count = cmd.ExecuteNonQuery();
}

答案 1 :(得分:0)

您是否尝试过以下操作?

R[atrName] += vrednost;

答案 2 :(得分:0)

尝试使用onli括号

[R [变量] = someValue中;