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()试试
    
    评论

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退