【发布时间】:2013-12-23 18:44:28
【问题描述】:
我正在尝试编写insert 语句,其中的工作是获取用户选择的选定项目,然后将其插入到他们的个人资料中。
我正在使用配置文件提供程序。
我在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:
问题是我不认为我的查询会这样做,因为它不起作用。
【问题讨论】:
-
您的
INSERT语句无效:您没有指定要插入的值(INSERT语句的VALUES部分)。 -
在哪里插入或在哪里更新?
-
我已经更新了问题
-
这不是重复的,因为另一个问的是不同的问题,我问的是我写语句的方式是否正确。
标签: c# sql database insert user-profile