日期:2014-05-18  浏览次数:20830 次

datagridview中的数据如何转换为长整型?
设计了一个页面,有datagridview。
点击其中一行,该行数据反映在窗口中的textbox中。
上面说的都实现了!在删除的时候遇到困难:

我设计的数据表中允许有重复的数据的!比如同一税种,金额也一样。一删就都删除了!
数据库是ACCESS, 只有自动编号长整型的“ID”字段不一样。


DATAGRIDVIEW 数据源取得如下列代码:能正常刷新显示,添加都正常。

protected string myolestr = "select id as 序号,kemucode as 科目代码,kemuname as 科目名称,jiefang as 借方金额,daifang as 贷方金额,jdren as 监督人 from tb_main";
? protected string mystrtb = "tb_main";
DataSet myds = boperate.getds(myolestr, mystrtb);
? dgvmain.DataSource = myds.Tables[0];


删除代码如下:

private void btndele_Click(object sender, EventArgs e)
? {
? try
? {
? if (MessageBox.Show("确定要删除该条信息吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
? {
? boperate.getcom("delete from tb_main where id='" + Convert.ToInt64(dgvmain[0, dgvmain.CurrentCell.RowIndex].Value) + "'");
? frm_pzluru_Load(sender, e);
? MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ?
? }
? }
? catch (Exception ex)

? {
? MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
? }
? }


但是系统提示“标准表达式数据类型不匹配”
无论我 Convert.To任何类型,貌似出来的都是字符型。



------解决方案--------------------
boperate.getcom("delete from tb_main where id='" + Convert.ToInt64(dgvmain[0, dgvmain.CurrentCell.RowIndex].Value) + "'");
单引号去掉