标题:C#数据库处理时遇到问题
只看楼主
小孔
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2016-2-25
结帖率:100%
已结贴  问题点数:20 回复次数:1 
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.Jet.OLEDB.4.0;Data Source=studentinfo.mdb";
            conn.Open();
            comm.Connection = conn;
             = "select * from studentinfo where '分数'>75";
            adapter.SelectCommand = comm;
            OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ds.Clear();
            adapter.Fill(ds, "good");
            d1.DataSource = ds.Tables["good"];
        }

        private void button2_Click(object sender, EventArgs e)
        {
            adapter.Update(ds, "good");
        }
 
    }
}
注:在adapter.Fill(ds,"good")这儿提示 :标准表达式中数据类型不匹配。
搜索更多相关主题的帖子: public 数据库 
2016-02-25 10:01
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:20 
我和教材上对比了一下,综合个人想法给个意见。好久没有用过数据库了,不过当时也没有学多少,还有吗,我觉得编程中少用中文为好。总之,我没看出来有什么错误的地方。
程序代码:
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;
        OleDbCommand comm;
        OleDbDataAdapter adapter;
        DataSet ds;
        OleDbCommandBuilder builder;
        
        public Form1()
        {
            InitializeComponent();
            //初始化变量
            conn = new OleDbConnection();
            comm = new OleDbCommand();
            adapter = new OleDbDataAdapter();
            ds = new DataSet();
        
            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=studentinfo.mdb";
            //conn.Open();  //这个好像不用打开
            comm.Connection = conn;
             = "select * from studentinfo where '分数'>75";
            adapter.SelectCommand = comm;
            //使用OleDbCommandBuilder注意,对应数据库表中要有主键,否则在执行修改和删除时会出错
            builder = new OleDbCommandBuilder(adapter);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ds.Clear();
            adapter.Fill(ds, "good");  //语法上看不出来有什么错误
            d1.DataSource = ds.Tables["good"];
        }

        private void button2_Click(object sender, EventArgs e)
        {
            adapter.Update(ds, "good");
        }

 
    }
}

PS:你可以百度一下'标准表达式中数据类型不匹配',里面有好多的案例,或许可以解决你的问题,很有可能是字段的数据类型搞错了。

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


   唯实惟新 至诚致志
2016-02-25 10:41



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




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

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