我正在尝试编写一个insert
语句,其中的作业是将用户选择的选定项目插入到其配置文件中。写入sql和插入语句的问题
我正在使用Profile提供程序。
我在UserProfile
表中有一个新列(用于存储用户名,年龄等信息),我称它为Rented
。
如:
- 用户
Tom45
- 租
Pirates of The caribbean
- 年龄
23
可能有人让我知道如果我这样做是正确的,因为我似乎无法得到它上班。
我的插入和SQL:
protected void Button3_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\ASPNetDB.mdb;Persist Security Info=True");
{
da.InsertCommand = new OleDbCommand("INSERT INTO UserProfile (Rented) VALUES (@Rented) WHERE [UserName] = ?", conn);
string dvdrent = DG_Latest.SelectedRow.Cells[1].Text;
OleDbParameter rented = new OleDbParameter();
{
da.InsertCommand.Parameters.AddWithValue("@Rented", DG_Latest.SelectedRow.Cells[2].Text);
}
conn.Open();
da.InsertCommand.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
}
我有这个表:
而且每个用户都有一个配置文件:
一旦他们登录后可以选择租用DVD S:
的问题是,我不认为我的查询做到这一点,因为这是行不通的。
你'INSERT'声明是无效的:你没有指定插入值(一个'INSERT'语句的'VALUES'部分)。 – Dai
插入哪里或更新哪里? – rach
我已经更新了这个问题 – Beep