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

(string)Eachcailiao.Rows[i].Cells[7].Value;改成Eachcailiao.Rows[i].Cells[7].Value.ToString()试试
weixin_44138934
wxy新人小白 没用
5 个月之前 回复

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

改成这样 试一下

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问