注册 登录
编程论坛 C# 论坛

C#数据库处理时遇到问题

小孔 发布于 2016-02-25 17:33, 2577 次点击
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace 综合查询
{
    public partial class Form1 : Form
    {
        OleDbConnection conn = new OleDbConnection();
        OleDbCommand comm = new OleDbCommand();
        OleDbDataAdapter adapter = new OleDbDataAdapter();
        DataSet ds = new DataSet();
   
        public Form1()
        {
            InitializeComponent();
            conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=studentinfo.mdb";
            conn.Open();
            comm.Connection = conn;
        }
      
        private void Form1_Load(object sender, EventArgs e)
        {
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strcomm;
            if (r1.Checked)
                strcomm = "select * from studentinfo where no= t1.Text";
            else if (r2.Checked)
                strcomm = "select * from studentinfo where name=t1.Text";
            else
                strcomm = "select * from studentinfo where score >t1.Text ";
             = strcomm;
            adapter.SelectCommand = comm;
            OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
            ds.Clear();
            adapter.Fill(ds,"good");    此处提示说:至少一个参数没有被指定值。
            data1.DataSource = ds.Tables["good"];
            adapter.Update(ds, "good");

        }
    }
}
9 回复
#2
qq10235692232016-02-25 23:38
程序代码:
//注意连接字符串的问题,还有非数字字段加引号。
if (r1.Checked)
    strcomm = "select * from studentinfo where no=" + t1.Text;
else if (r2.Checked)
    strcomm = "select * from studentinfo where name='" + t1.Text + "'";
else
    strcomm = "select * from studentinfo where score>" + t1.Text;


[此贴子已经被作者于2016-2-25 23:41编辑过]

#3
小孔2016-02-26 09:32
回复 2楼 qq1023569223
你这个符号加的看不懂,但是还是运行不出来
#4
qq10235692232016-02-26 10:29
你身边没有教材吗?按教材写不会出错的。看你写得很乱。
1