wxy新人小白 2019-11-04 22:41 采纳率: 31.3%
浏览 304

为什么我添加完数据后,数据库里的没问题,在软件的datagridview上显示的不对

图片说明
图片说明

图片说明

先按添加按钮,出现第一个图来添加参数,确认后在第三幅图的datagridview上显示出来。(删除时要用材料特性ID做条件)

问题:第二图没问题(string tabText = System.Guid.NewGuid().ToString("N") + DateTime.Now.ToString("yyyyMMddHHmmss");随机生成的ID)
第三图中材料特性ID只显示了前面的数字
部分程序如下

private void btntianjia_Click(object sender, EventArgs e)
        {
            string btnName = btntianjia.Text;
            main1.form1.toolOperation.Text = "正在加载窗体,请稍等...";
            main1.form1.toolOperation.Font = new Font(main1.form1.toolOperation.Font, FontStyle.Bold);
            main1.form1.toolOperation.ForeColor = Color.FromArgb(254, 67, 101);
            Application.DoEvents();
            Addcailiaoquxian form = new Addcailiaoquxian();
            Addcailiaoquxian.form1.BtnName = btnName;
            form.Show();
            main1.form1.toolOperation.Text = "";
        }

Addcailiaoquxian窗口的

private void btnAdd_Click(object sender, EventArgs e)
        {
            string dbPath = @"D:\历年高考分数.db";
            if (btnName == "添加")
            {

                    string sq = @"Data Source=" + dbPath;
                    m = new SQLiteConnection(sq);
                    m.Open();
                    string sql = "select * from sqlite_master where type='table' and name ='特性'";
                    SQLiteCommand command = new SQLiteCommand(sql, m);//
                    m.Close();
                    AddcailiaoPara1(dbPath, "特性");
                    Guanlicailiaoquxian.form1.LoadcailiaoPara();
                    DialogResult result = MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);


            }

        }
        public void AddcailiaoPara1(string dbPath, string tableName)
        {
            string yinsu = "";
            if (radioButton2.Checked == true) { yinsu = "紫外线"; }
            else if (radioButton1.Checked == true) { yinsu = "温度、振动"; }
            string tabText = System.Guid.NewGuid().ToString("N") + DateTime.Now.ToString("yyyyMMddHHmmss");

            string str = "'" + txtName.Text + "'," + "'" + txtyunxinglicheng.Text + "'," + "'" + txtyingdu.Text + "'," + "'" + txtladuanshenchanglv.Text + "'," + "'" + txtlashenqiangdu.Text + "'," + "'" + yinsu + "'," + "'" + tabText + "'";
            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();
        }

删除使用的

 for (int i = 0; i < Eachcailiao.Rows.Count; i++)
                {
                    DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)Eachcailiao.Rows[i].Cells[0];
                    Boolean flag = Convert.ToBoolean(checkCell.Value);
                    if (flag == true)
                    {
                        string dbPath = @"D:\历年高考分数.db";
                        string sq = @"Data Source=" + dbPath;
                        SQLiteConnection m = new SQLiteConnection(sq);
                        m.Open();
                        string sql = "delete from 特性 where 材料特性ID='" + Eachcailiao.Rows[i].Cells[7].Value + "'";
                        SQLiteCommand command = new SQLiteCommand(sql, m);
                        command.ExecuteNonQuery();
                        m.Close();
                    }
                }
  • 写回答

1条回答 默认 最新

  • PCYaoYao 2019-11-05 11:26
    关注

    考虑问题是字段显示长度的问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条