wxy新人小白 2019-11-01 18:08 采纳率: 31.3%
浏览 1490

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条回答

  • Json-Huang 2019-11-01 19:27
    关注
    (string)Eachcailiao.Rows[i].Cells[7].Value;改成Eachcailiao.Rows[i].Cells[7].Value.ToString()试试
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料