weixin_44138934
wxy新人小白
采纳率72%
2019-11-01 18:08 阅读 982

C#winform中显示无法将类型为“System.Int64”的对象强制转换为类型“System.String”

图片说明
图片说明

string yinsu = "";
            if (radioButton2.Checked == true) { yinsu = "紫外线"; }
            else if (radioButton1.Checked == true) { yinsu = "温度、振动"; }
            string id = System.Guid.NewGuid().ToString("N") + DateTime.Now.ToString("yyyyMMddHHmmss");
            string str = "'" + txtName.Text + "'," + "'" + txtyunxinglicheng.Text + "'," + "'" + txtyingdu.Text + "'," + "'" + txtlashenqiangdu + "'," + "'" + txtladuanshenchanglv + "'," + "'" + yinsu + "'," + "'" + id + "'";
            string sq = @"Data Source=" + dbPath;
            m = new SQLiteConnection(sq);
            m.Open();
            string sql = "insert into " + tableName + " (传感器型号,运行里程,硬度,拉伸强度,拉断伸长率,因素,材料特性ID) values (" + str + ")";
            SQLiteCommand command = new SQLiteCommand(sql, m);
            command.ExecuteNonQuery();
            m.Close();

问题1:原本打算自动生成一个id(string),在系统管理界面添加一组数,结果在dataGridView上材料特性ID显示为0,而数据库里显示为很长的一串字符

问题二:按修改按钮后 ,在Addcailiaoquxian.form1.TabText = (string)Eachcailiao.Rows[i].Cells[7].Value;//
处显示无法将类型为“System.Int64”的对象强制转换为类型“System.String”。如何处理

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • hjs218 Json-Huang 2019-11-01 19:27
    (string)Eachcailiao.Rows[i].Cells[7].Value;改成Eachcailiao.Rows[i].Cells[7].Value.ToString()试试
    
    点赞 评论 复制链接分享
  • gxygzy gxygzy 2019-11-04 11:53

    Convert.ToString(Eachcailiao.Rows[i].Cells[7].Value)

    改成这样 试一下

    点赞 评论 复制链接分享

相关推荐