c# - 通过复选框更新列和多个更新
问题描述
感觉这应该不是一件容易的事。如何通过带有列名的复选框更新我的 sql server 表;
DROP TABLE #indebtedness
CREATE TABLE [dbo].[indebtedness](
[Subscriber_No] [bigint] NULL,
[Subscriber_Name] [nvarchar](max) NULL,
[Last_Deact_Date] [date] NULL,
[allocated] [decimal](18, 3) NULL,
[collected] [numeric](18, 3) NOT NULL,
[ID_No] [bigint] NULL,
我正在使用带有 c# 代码的桌面应用程序,我需要检查框以从 dataGridView 更新列
我使用类似这样的代码来更新我的数据库
int countSuccess = 0;
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
// INSERT command:
using (SqlCommand com = new SqlCommand("UPDATE indebtedness SET autodialtype=@autodialtype,autodial=@autodial,autodate=@autodate,lastdate=@lastdate,lastcall_case=@lastcall_case WHERE Subscriber_No=@Subscriber_No and company_name=@company_name and indebtedness_name=@indebtedness_name", con))
{
com.Parameters.AddWithValue("@company_name", company_name.Text);
com.Parameters.AddWithValue("@indebtedness_name", indebtedness_name.Text);
com.Parameters.AddWithValue("@Subscriber_No", dataGridView1.Rows[i].Cells[0].Value);
com.Parameters.AddWithValue("@autodialtype", dataGridView1.Rows[i].Cells[1].Value);
com.Parameters.AddWithValue("@autodial", "Called");
com.Parameters.AddWithValue("@autodate", DateTime.Today.ToShortDateString());
com.Parameters.AddWithValue("@lastcall_case", "AutoDial");
com.Parameters.AddWithValue("@lastdate", DateTime.Today.ToShortDateString());
int numUpd = com.ExecuteNonQuery();
countSuccess += numUpd;
//com.ExecuteNonQuery();
}
}
MessageBox.Show($"Successfully UPDATED {countSuccess} of {dataGridView1.Rows.Count} rows");
我只想更新我只检查更新的列
解决方案
推荐阅读
- web - 如何沿路由路径移动带有动画的标记?
- azure-sql-database - 将 MSI 令牌传递给 flyway 命令行
- google-apps-script - 如何优化我的 Google Apps 脚本使其不超过最大超时?
- gnuplot - gnuplot 5 多图对齐不向后兼容
- dataframe - DataFrame 定义是惰性求值
- javascript - 试图将一页数据传递到下一页,但不幸的是数据未显示
- javascript - 在 React 组件之间传递数据
- python - 用 x 轴在列中绘制 pandas groupby
- javascript - 在触发动作之前,有什么方法可以等待加载 Bootstrap 模式?
- css - 在网格自动行中正确设置图像样式