【发布时间】:2020-03-24 04:37:34
【问题描述】:
您好,我目前正在研究图书馆系统,我确实想查看特定成员拥有多少本书。
每当我向学生发行一本书时,我都想为他们添加一份副本。
我试过了:
public void StudentPossession()
{
cm = new SqlCommand("INSERT INTO tblStudent(stCopies) VALUES (@stCopies)", cn);
cm.Parameters.AddWithValue("@stCopies", txtCopies.Text);
cm.ExecuteNonQuery();
}
但它不会插入成员行,而是显示
|-------------|---------------|------------|
| ID | studNumber | Copies |
|-------------|---------------|------------|
| 1 | 34543534 | NULL |
|-------------|---------------|------------|
| 2 | NULL | 1 |
|-------------|---------------|------------|
我也试过了:
cm = new SqlCommand("INSERT INTO tblStudent(stCopies) VALUES (@stCopies) WHERE studNumber ='" + txtStudNumber.Text + "'", cn);
但也不行。
我不知道如何解决此问题,因此我们将不胜感激。或者有什么方法可以做到这一点?
【问题讨论】:
-
如果您只为
stCopies传递一个值,为什么您期望studNumber被填充?你认为studNumber来自哪里? -
@John 我怎样才能将值传递给我的 studNumber 或条件,以便将其插入到学生的行中?
-
您要插入新行还是更新现有行?
-
“我忘了说我已经为学生行设置了值” - 我没有关注?你说你正在插入新记录,所以你没有当前 studNumber 的学生行,对吗?如果术语出现问题:数据库表中的一行就是一条记录。
-
I [suck] at explaining好吧,好消息是计算机的脾气特别好。