怎样实现点击button查询从数据库中找出符合条件的结果。。。求问(以下代码可以否)

 try
            {
                string sql = string.Format("select classId,loginId,studentName,studentNo,userState From student left join userstate on student.userstateId=userState.userStateId where student.StudentName like '%{0}%'", txtStudentName.Text.Trim());
                SqlCommand command = new SqlCommand(sql, DBHelper.connection);

                DBHelper.connection.Open();      //DBHelper为一个类
                SqlDataReader dataReader = command.ExecuteReader();
                lv.Items.Clear();
                if (!dataReader.HasRows)
                {
                    MessageBox.Show("没有找到您要查找的学生");
                    return;
                }
                string loginId;
                string studentName;
                string studentNo;
                string userState;
                while (dataReader.Read())
                {
                    loginId = dataReader["loginId"].ToString();
                    studentName = dataReader["studentName"].ToString();
                    studentNo = dataReader["studentNo"].ToString();
                    userState = dataReader[4].ToString();

                    ListViewItem lviStuden = new ListViewItem(loginId);

                    lviStuden.Tag = (int)dataReader["studentName"];
                    lv.Items.Add(lviStuden);
                    lviStuden.SubItems.AddRange(new string[] { studentName, studentNo, userState });
                }
                dataReader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("查询出错!");


            }
            finally
            {
                DBHelper.connection.Close();
            }
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,针对你的题,我给以下代码实现思路: 首先,你需要在 Vue 实例定义一个数组,用来存储从数据库查询来的数据,例如: ```javascript data() { return { dataList: [] // 数据库查询结果存储数组 } } ``` 接下来,在点添加按钮时,你可以通过 Vue 的生命周期钩子函数 `mounted()` 发起 Ajax 请,从数据库查询数据,然后将查询结果存储在 `dataList` 数组,例如: ```javascript mounted() { this.$http.get('/api/data').then(response => { this.dataList = response.data }) } ``` 这里使用了 axios 库发送 Ajax 请,你需要在项目安装并引入该库。 最后,在表单实现添加一行数据的功能,你可以通过列表渲染的方式,将 `dataList` 数组的数据渲染到表格,并通过表单提交的方式将新添加的数据提交到服务器,例如: ```html <table> <thead> <tr> <th>名称</th> <th>价格</th> </tr> </thead> <tbody> <tr v-for="(item, index) in dataList" :key="index"> <td>{{ item.name }}</td> <td>{{ item.price }}</td> </tr> </tbody> </table> <form> <input type="text" name="name" placeholder="名称"> <input type="text" name="price" placeholder="价格"> <button type="submit">添加</button> </form> ``` 在提交表单时,你可以通过 Ajax 请将新添加的数据提交到服务器,并将其添加到 `dataList` 数组,例如: ```javascript submitForm() { const formData = new FormData(document.querySelector('form')) this.$http.post('/api/data', formData).then(response => { this.dataList.push(response.data) }) } ``` 这里使用了 FormData 对象将表单数据序列化,并使用 axios 库发送 POST 请向服务器提交数据。 综上,以上是一个简单的用 Vue 实现添加按钮,从数据库查询并将查询结果添加到表单,表单实现添加一行数据功能的实现思路。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值