标题:C#数据库处理时遇到问题
只看楼主
小孔
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2016-2-25
结帖率:100%
已结贴  问题点数:10 回复次数:9 
C#数据库处理时遇到问题
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");

        }
    }
}
搜索更多相关主题的帖子: public 数据库 
2016-02-25 17:33
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:10 
程序代码:
//注意连接字符串的问题,还有非数字字段加引号。
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编辑过]


   唯实惟新 至诚致志
2016-02-25 23:38
小孔
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2016-2-25
得分:0 
回复 2楼 qq1023569223
你这个符号加的看不懂,但是还是运行不出来
2016-02-26 09:32
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:0 
你身边没有教材吗?按教材写不会出错的。看你写得很乱。

   唯实惟新 至诚致志
2016-02-26 10:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-461944-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.093101 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved