- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试从 datagridview 中删除一条记录,然后将其更新到 mysql 服务器,但是我一直收到“并发冲突:DeleteCommand 影响了预期的 1 条记录中的 0 条记录。”。我已经用谷歌搜索并稍微弄乱了它,但无法找到解决爱情和金钱的方法。我哪里错了?
private void Form1_Load(object sender, EventArgs e)
{
try
{
// create a connection to the server
connection = new MySqlConnection("SERVER=" + Constants.SERVER + ";" + "DATABASE=" + Constants.DATABASE + ";UID=" + Constants.USERNAME + ";" + "PASSWORD=" + Constants.PASSWORD + ";");
connection.Open();
// create our default handler
adapter = new MySqlDataAdapter();
// set the default commands to do
adapter.SelectCommand = new MySqlCommand("SELECT * FROM npc_drops", connection);
MySqlCommand query = new MySqlCommand("DELETE FROM npc_drops WHERE id = @id", connection);
query.Parameters.Add("@id", MySqlDbType.Int32, 10, "id");
adapter.DeleteCommand = query;
// create a table to put our data in and fill it with the results
table = new DataTable();
adapter.Fill(table);
// bind both the data table and the datagridview togeather
BindingSource source = new BindingSource();
source.DataSource = table;
dataGridView1.DataSource = source;
dataGridView1.Columns["id"].Visible = false;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
table = table.GetChanges();
adapter.Update(table);
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
表:
CREATE TABLE `npc_drops` (
`id` INT(10) NULL AUTO_INCREMENT,
`npcs` VARCHAR(250) NULL DEFAULT NULL,
`rate` INT(3) NULL DEFAULT NULL,
`item` INT(5) NULL DEFAULT NULL,
`amount` INT(10) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
最佳答案
我知道这是一个旧线程,但我遇到了同样的问题并找到了解决方案。也许其他人会在这里看到它。
使用 Visual Studio,在 .xsd 文件中,数据适配器中有一个 DELETE 命令。该命令的形式为 SQL“DELETE from table where column1 = @Original_column1 AND column2 = @Original_column2 AND...”默认情况下,它将所有列与您读取数据库时的值进行比较,并且不会删除记录,除非它们都匹配。这是为了避免在您阅读记录和尝试更改记录之间覆盖其他人所做的更改。
问题来了。如果这些列中的任何一个在数据库中为 NULL,它将不匹配并按照您的描述出错。
PS:在使用 VS db 库时,除了在 DB 中允许 NULL 之外,我什么都没有。 LINQ2SQL 或其他名称...
关于c# - 并发冲突 : the DeleteCommand affected 0 of the expected 1 records,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10711342/
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我是脚本新手。如何编写 Expect 脚本以通过 ssh 连接到设备并提示用户输入密码?我们使用 pin + RSA token 代码作为密码,因此我无法存储密码。 #!/usr/bin/expect
我编写了以下代码并尝试执行它。但我在执行 do {”时遇到“无效的命令名称“do”” 代码: #!/usr/bin/expect set val 0; set input 5; do { pu
我已经查看了 Expect 联机帮助页并用 Google 搜索了它,但我还没有找到 expect 的 -r 是什么。我看到这个选项以前是这样用的 expect -r "\r\n\r\n" 在 expe
我的 shebang 看起来像这样: #!/usr/bin/expect -d 当我从命令行运行脚本时,它会提供我想要的内容。 但是,我通过 crontab 运行这个脚本。是否可以将调试开关保持打开状
我是 Expect 脚本的新手。 我在 Linux 机器上为 ssh 编写了一个 Expect 脚本,在那里我在 ssh 到不同的 Linux 机器时遇到了问题。下面我复制了脚本。 !/usr/loc
Scene 1, Layer 'script', Frame 1, Line 9 1084: Syntax error: expecting identifier before this. Sc
我正在运行调试命令以将命令的输出记录到文件中。我尝试了 log_file 命令,但它没有记录输出。我的代码如下: log_file -a gdb.txt send "~/debugulator.sh
我希望 expect_user 有一个无限的(或非常大的)超时和 expect 的默认超时。有没有办法设置不同的超时?或者我是否只需要在每次更改用途之前手动执行此操作? 最佳答案 expect 和ex
我正在学习 iOS 编程(我来自 Android),我正在寻找更容易获取字符串的方法。有了这个建议,我定义了下一个宏并在一些代码片段中使用它: #define STRING_BASE @"InfoPl
你好我是 rspec 的新手,我想弄清楚将 block 传递给 expect{} 和只使用 expect() 之间的区别 这是一个简单的例子 require "rails_helper" RSpec.
我正在尝试为 React JS 运行单元测试 - 使用 jest/enzyme。 目前测试失败。不太清楚为什么,也许我没有正确调用 expect(wrapper.find)。这是我测试的一部分: F
例如,现在我有一个“root.exp”期望脚本如下: spawn ssh user@ip expect "Password:" send "password" 然后,我要发送到这个ssh服务器的exp
您好,我是 Expect 脚本编写的新手,我一直在尝试使用以下方法将 IP 地址获取到变量中: set timeout -1 spawn $env(SHELL) match_max 100000 se
expect.anything() 不适用于 expect.toBe(),但适用于 expect.toEqual() test("this will pass", () => { expect("
我有一个如下所示的简单脚本,从命令行读取 2 个数字并将它们加在一起: $cat runexp.sh #!/bin/bash echo "read 1st number" read n1 echo "
当 Linux 机器的 $IP 登录后询问密码时,下面的 expect 脚本工作正常 但在某些情况下,某些Linux机器不需要ssh密码(我们可以不用密码登录), 所以我需要更改我的期望脚本以支持没有
我正在尝试使用 expect 远程登录服务器并更改用户密码。该应用程序要求,如果您要更改的密码包含特殊字符,则将其引用。问题是,还需要引用 expect send 语句,当我尝试将两者结合起来时,脚本
下面这个简单的 expect 脚本的目标是获取远程机器上的 hostname 名称 有时期望脚本无法执行到 $IP_ADDRESS 的 ssh(因为远程机器不活动等) 所以在这种情况下,expect
我试图创建一个宏来替换, first: Some(first.as_ref().parse::().expect("Could not parse 'first'")) 我在其他模块(如 Clap w
我是一名优秀的程序员,十分优秀!