将所选插入语句添加到用户配置文件c# [英] add selected insert statement to users profile c#
问题描述
大家好我试着写一个声明将所选数据插入到用户个人资料中
因此用户可以选择DVD然后当他们点击租金时它会显示在那里他们租用了什么。
到目前为止的代码
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(?)WHERE([UserName] =?);,conn);
da.InsertCommand.Parameters.AddWithValue( @?,DG_Latest .SelectedRow.Cells [ 2 ]。文字);
conn.Open();
da.InsertCommand.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
}
所以这段代码对我来说不起作用我运行它并点击我得到的按钮
在SQL语句结束时缺少分号(;)。
你可以' t使用带INSERT的WHERE子句。
INSERT 始终 创建新记录,它不能改变现有记录。
可能你想要一个UPDATE命令:
UPDATE UserProfile SET Rented = @Rented WHERE [UserName] = @ User但是,我不会这样做 - 我有一个单独的租用表,它存储了DVD ID,客户ID,租赁日期和退货日期。
那样,客户可以在周末借用两张DVD而不需要系统,如果客户说出磁盘已损坏而无法播放,或者完全错误的磁盘,您可以回溯到之前的租用者
Hi guys im trying to write a statement to insert selected data into a users profile
So a user can select a dvd then when they click rent it will show in there profile what they have rented.
Code so far
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 (?) WHERE ([UserName] = ?);", conn);
da.InsertCommand.Parameters.AddWithValue("@?", DG_Latest.SelectedRow.Cells[2].Text);
conn.Open();
da.InsertCommand.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
}
So this code is not working for me evry time i run it and click on the button i get
Missing semicolon (;) at end of SQL statement.
You can't use a WHERE clause with INSERT.
INSERT always create a new record, it can't change existing ones.
Probably you want an UPDATE command instead:
UPDATE UserProfile SET Rented=@Rented WHERE [UserName]=@UserBut, I wouldn't do it like that - I'd have a separate table for rented, which stored the DVD ID, the customer ID, the date of rental, and the date of return.
That way, the customer can borrow two DVDs for the weekend without your sytem having a fit, and you can "backtrack" to the previous renter if a customer comes in to say the disk is damaged and won't play, or is the wrong disk entirely.
这篇关于将所选插入语句添加到用户配置文件c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!