wxy新人小白 2019-11-07 10:42 采纳率: 31.3%
浏览 761
已采纳

在C#winform中怎么让添加一些参数后,这行数据的ID自动加一

图片说明

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

                    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, "特性");
                    if (command.ExecuteScalar() == null)
                    {
                        m.Close();
                        NewTable1(dbPath, "特性");
                        AddcailiaoPara1(dbPath, "特性");
                    }
                    else
                    {
                        m.Close();
                        AddcailiaoPara1(dbPath, "特性");
                    }

                }
                else
                {
                    NewDbFile(dbPath);
                    NewTable1(dbPath, "特性");
                    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 id = ?
            //string tabText = txtName.Text + yinsu;
            //string str = "'" + txtName.Text + "'," + "'" + txtyunxinglicheng.Text + "'," + "'" + txtyingdu.Text + "'," + "'" + txtlashenqiangdu + "'," + "'" + txtladuanshenchanglv + "'," + "'" + yinsu + "'," + "'" + id + "'";
            string str = "'" + txtName.Text + "'," + "'" + txtyunxinglicheng.Text + "'," + "'" + txtyingdu.Text + "'," + "'" + txtlashenqiangdu.Text + "'," + "'" + txtladuanshenchanglv.Text + "'," + "'" + 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();
        }

怎么让添加一些参数后,这行数据的ID自动加一,以便于以后根据id删除数据
string id那应该怎么写

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-11-07 10:44
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法