datagridview中我选择的是DataGridViewCheckBoxColumn类型,要的结果是如果选中我要得到1,如果没选中得到0,但现在当我把选中的标记取消后再保存,就会出现“ 该字符串未被识别为有效的字符串”这样的错误。
下面是相应的存储过程:
create proc proc_UpdateDuty ----------------------根据员工编号录入周六值班信息
(
@UserID varchar(100), -------------------员工编号
@UserDutyDate datetime, -------------------要录入值班信息的日期。格式如:2008-07-01 00:00:00。
@UserDuty int -------------------是否值班。值班:1;休息 0。
)
as
begin
update tb_WeekEndDuty set UserDuty=@UserDuty where UserID=@UserID and Year(UserDutyDate)=Year(@UserDutyDate) and Month(UserDutyDate)=Month(@UserDutyDate) and Day(UserDutyDate)=Day(@UserDutyDate)
end
go
这是更改数据的方法:
private void UpdateDuty(string UserID, DateTime UserDutyDate, int UserDuty)
{
SqlParameter[] sp = new SqlParameter[] {
new SqlParameter("@UserID",SqlDbType.VarChar,100),
new SqlParameter("@UserDutyDate",SqlDbType.DateTime),
new SqlParameter("@UserDuty",SqlDbType.Int)
};
sp[0].Value = UserID;
sp[1].Value = UserDutyDate;
sp[2].Value = UserDuty;
db.Exec_SQL("proc_UpdateDuty", sp);
}调用上面的方法:
private void button7_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor; foreach (DataGridViewRow dgvRow in this.dgvSAT_Officer.Rows)
{
if (dgvRow.Index != -1)
{
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[3].HeaderText.ToString()), bool.Parse(dgvRow.Cells[3].Value.ToString()) ? 1 : 0);
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[4].HeaderText.ToString()), bool.Parse(dgvRow.Cells[4].Value.ToString()) ? 1 : 0);
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[5].HeaderText.ToString()), bool.Parse(dgvRow.Cells[5].Value.ToString()) ? 1 : 0);
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[6].HeaderText.ToString()), bool.Parse(dgvRow.Cells[6].Value.ToString()) ? 1 : 0);
if (this.dgvSAT_Officer.Columns[7].Visible)
{
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[7].HeaderText.ToString()), bool.Parse(dgvRow.Cells[7].Value.ToString()) ? 1 : 0);
}
}
} this.BindDGView("职员", this.dgvSAT_Officer);
this.BindWork("周六", this.crystalReportViewer2, "职员"); this.Cursor = Cursors.Default;
MessageBox.Show("职员周六值班排班信息已成功保存!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
下面是相应的存储过程:
create proc proc_UpdateDuty ----------------------根据员工编号录入周六值班信息
(
@UserID varchar(100), -------------------员工编号
@UserDutyDate datetime, -------------------要录入值班信息的日期。格式如:2008-07-01 00:00:00。
@UserDuty int -------------------是否值班。值班:1;休息 0。
)
as
begin
update tb_WeekEndDuty set UserDuty=@UserDuty where UserID=@UserID and Year(UserDutyDate)=Year(@UserDutyDate) and Month(UserDutyDate)=Month(@UserDutyDate) and Day(UserDutyDate)=Day(@UserDutyDate)
end
go
这是更改数据的方法:
private void UpdateDuty(string UserID, DateTime UserDutyDate, int UserDuty)
{
SqlParameter[] sp = new SqlParameter[] {
new SqlParameter("@UserID",SqlDbType.VarChar,100),
new SqlParameter("@UserDutyDate",SqlDbType.DateTime),
new SqlParameter("@UserDuty",SqlDbType.Int)
};
sp[0].Value = UserID;
sp[1].Value = UserDutyDate;
sp[2].Value = UserDuty;
db.Exec_SQL("proc_UpdateDuty", sp);
}调用上面的方法:
private void button7_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor; foreach (DataGridViewRow dgvRow in this.dgvSAT_Officer.Rows)
{
if (dgvRow.Index != -1)
{
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[3].HeaderText.ToString()), bool.Parse(dgvRow.Cells[3].Value.ToString()) ? 1 : 0);
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[4].HeaderText.ToString()), bool.Parse(dgvRow.Cells[4].Value.ToString()) ? 1 : 0);
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[5].HeaderText.ToString()), bool.Parse(dgvRow.Cells[5].Value.ToString()) ? 1 : 0);
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[6].HeaderText.ToString()), bool.Parse(dgvRow.Cells[6].Value.ToString()) ? 1 : 0);
if (this.dgvSAT_Officer.Columns[7].Visible)
{
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[7].HeaderText.ToString()), bool.Parse(dgvRow.Cells[7].Value.ToString()) ? 1 : 0);
}
}
} this.BindDGView("职员", this.dgvSAT_Officer);
this.BindWork("周六", this.crystalReportViewer2, "职员"); this.Cursor = Cursors.Default;
MessageBox.Show("职员周六值班排班信息已成功保存!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
解决方案 »
- asp.net 输出加号............................................在线等
- vs2010 rdlc问题
- c# windows应用程序 播放器控件 有没有详细操作
- webBrowser控件奇怪的问题
- c#调用vc++编写的dll
- 请问xml中这两个的区别:<BARCODE /> 与<BARCODE></BARCODE>
- WinForm 里面有哪个容器有垂直滚动条
- gridview调用问题!!!!!!!!!!!!!!!!!!!!!!!!!!!1
- 那个怎么用c#操作MySql啊?
- 大家谈谈还未很成熟的C#,学它有没有较长远的前作呢?还是java牛一点呢?
- EXCEL导入MSSQL问题
- treeview HideSelection 设为false 后虽然选择中的节点可见,但几乎可不见,不醒目
改成把
int flag=0;
DataGridViewCheckBoxColumn colunm = (DataGridViewCheckBoxColumn)dgvRow.Cells[3];
if(colunm.Selected)
{
flag = 1;
}
然后
this.UpdateDuty(dgvRow.Cells[0].Value.ToString(), DateTime.Parse(this.dgvSAT_Officer.Columns[7].HeaderText.ToString()), flag); 大概意思是这样