C# wince5.0下的插入、删除、更新源码

本文档展示了如何在C#环境下,针对WinCE5.0系统进行数据库操作,包括使用SqlServerCe进行数据查询、插入、更新和删除的详细源码。通过`CommonDB`类与`NoteDB`类实现了对Notes表的操作,提供了完整的参数化SQL示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlServerCe;
using System.IO;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using DeviceApplication5.DataAccess;

namespace DeviceApplication5.Business
{
    class NoteDB
    {
        private DataGrid Notedgrid;
        private BindingSource Bding;
        public NoteDB()
        {

        }
        public NoteDB(BindingSource bds, DataGrid dgrid)
        {
            Notedgrid = dgrid;
            Bding = bds;
        }
        public DataSet GetNoteData()
        {
            CommonDB cdb = new CommonDB();
            string Sql = "select * from Notes";
            DataSet Ds = cdb.GetDataSet(Sql, "Notes");
            return Ds;
        }
        public int InsertNoteData(Notes ns)
        {
            CommonDB cdb = new CommonDB();
            string Sql = "insert into Notes(NoteID,Author,Age,Phone,Address,PostCard)values(@noteid,@author,@age,@phone,@address,@postcard)";
            SqlCeParameter[] paras = new SqlCeParameter[6];
            paras[0] = new SqlCeParameter("@noteid", ns.NoteID);
            paras[1] = new SqlCeParameter("@author", ns.Author);
            paras[2] = new SqlCeParameter("@age", ns.Age);
            paras[3] = new SqlCeParameter("@address", ns.Address);
            paras[4] = new SqlCeParameter("@phone", ns.Phone);
            paras[5] = new SqlCeParameter("@postcard", ns.PostCard);
            
            return cdb.ExcuteSql(Sql, paras);

        }
        public int UpdateNoteDataByNotID(Notes ns)
        {
            CommonDB cdb = new CommonDB();
            string Sql = "update Notes set Author=@author,Age=@age,Phone=@phone,Address=@address,PostCard=@postcard where NoteID=@noteid";
            SqlCeParameter[] paras = new SqlCeParameter[6];
            paras[0] = new SqlCeParameter("@author", ns.Author);
            paras[1] = new SqlCeParameter("@age", ns.Age);
            paras[2] = new SqlCeParameter("@address", ns.Address);
            paras[3] = new SqlCeParameter("@phone", ns.Phone);
            paras[4] = new SqlCeParameter("@postcard", ns.PostCard);
            paras[5] = new SqlCeParameter("@noteid", ns.NoteID);
            return cdb.ExcuteSql(Sql, paras);
        }
        public int DeleteNoteDataByNotID(string Noteid)
        {
            CommonDB cdb = new CommonDB();
            string Sql = "delete Notes where NoteID=@noteid";
            SqlCeParameter[] paras = new SqlCeParameter[1];
            paras[0] = new SqlCeParameter("@noteid", Noteid);
            return cdb.ExcuteSql(Sql, paras);
        }
        public void UpdateGird()
        {
            DataSet Ds = GetNoteData();
            Bding.DataSource = Ds.Tables[0].DefaultView;
            Notedgrid.DataSource = Bding;
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值