用VisualC#来修改和删除数据库记录

VS2019 C# MySQL 学生信息增删改查(一、增删) VS2019 C# MySQL 学生信息增删改查 由于刚刚学习VS2019,入手的第一个例子是编写一个简单的增删改查。这里,我以学生信息为例,进行详细的过程描述以及代码实现。 一、 新建一个Windows窗体应用程序 1、创建新项目界面,如下图所示。 2、更改项目名称,当然不修改也可以。我这里的是“StudentInfoSystem”;项目存放位置路径根据自己需要进行更改;“将解决方案和项目放在同一目录中”前面的勾选框,选不选都可以;点击“创建”,如下图所示。 二、前期准备工作 1、将Form1属性中 阅读详情
在以前的一篇文章《Visual C#中轻松浏览数据库记录》中,我们介绍了用Visual C#如何把数据表中的字段值绑定到文本框的属性上和如何操作数据记录指针,随意浏览数据表中的记录。本文就接着上一篇的内容,来介绍用Visual C#如何来修改和删除数据记录。

一.程序设计和运行的环境设置:
(1).视窗2000服务器版
(2).Microsoft Access Data Component 2.6 以上版本 ( MADC 2.6 )
(3).本文程序使用的数据库的介绍:

为了方便起见,在选用数据库方面选用了本地数据库Access 2000,当然你也可以选用其他类型的数据库,只需要更改文章后面的程序源代码中数据库的引擎,并更改对应的代码就可以了。本程序中使用的数据库名称为sample.mdb,在此数据库中有一张数据表books。此数据表的结构如下:
字段名称 字段类型 代表意思
Bookid 数字 序号
booktitle 文本 书籍名称
bookauthor 文本 书籍作者
bookprice 数字 价格
bookstock 数字 书架号

二.程序设计难点和应该注意的问题:
在程序设计中的重点和难点就是如何用Visual C#删除记录和如何修改记录。下面就这二个问题进行必要的论述:
(1).如何用Visual C#正确删除数据表中的记录:

在用Visual C#删除记录的时候要注意的是:必须从二个方面彻底删除记录,即从数据库和用Visual C#编程时产生的一个DataSet对象中彻底删除。在程序设计的时候,如果只是删除了DataSet对象中的记录信息,这种删除是一种伪删除。这是因为当他退出程序,又重新运行程序,会发现,那个要删除的记录依然还存在。这是因为DataSet对象只是对数据表的一个镜像,并不是真正的记录本身。但如果只是从数据库中删除记录,因为我们此时程序用到的数据集合是从DataSet对象中读取的,子DataSet对象中依然保存此条记录的镜像。所以就会发现,我们根本没有删除掉记录,但实际上已经删除了。此时只有退出程序,重新运行,才会发现记录已经删除了。本文使用的方法是删除以上二个方面的记录或记录镜像信息。当然你也可以使用其他的方法,譬如:首先从数据库中删除记录,然后重新建立数据连接,重新创建一个新的DataSet对象。这种方法虽然也可以达到相同目的,但显然相对繁杂些,所以本文采用的是第一种方法--直接删除。在程序中具体的实现语句如下:
//连接到一个数据库
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;
string strDele = "DELETE FROM books WHERE bookid= " + t_bookid.Text ;
OleDbCommand myCommand = new OleDbCommand ( strDele , myConn ) ;
//从数据库中删除指定记录
myCommand.ExecuteNonQuery ( ) ;
//从DataSet中删除指定记录信息
myDataSet.Tables [ "books" ] . Rows [ myBind.Position ] . Delete ( ) ;
myDataSet.Tables [ "books" ] . AcceptChanges ( ) ;
myConn.Close ( ) ;

(2).用Visual C#来修改数据表中的记录:
在用Visual C#修改记录和删除记录,在程序设计中大致差不多,具体的实现方式也是通过SQL语句调用来实现的。下面就是在程序中修改记录的具体语句:
//连接到一个数据库
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;

//从数据库中修改指定记录
string strUpdt = " UPDATE books SET booktitle = '"
+ t_booktitle.Text + "' , bookauthor = '"
+ t_bookauthor.Text + "' , bookprice = "
+ t_bookprice.Text + " , bookstock = "
+ t_bookstock.Text + " WHERE bookid = " + t_bookid.Text ;

OleDbCommand myCommand = new OleDbCommand ( strUpdt , myConn ) ;
myCommand.ExecuteNonQuery ( ) ;
myConn.Close ( ) ;



(3).在了解了如何用Visual C#删除和修改记录以后,结合《Visual C#中轻松浏览数据库记录》文的内容,就可以得到用Visual C#完成删除和修改数据记录的比较完整程序代码,以下是本文中介绍程序的运行后的程序界面:


点击小图放大,本文中程序运行后的界面

三.用Visual C#实现删除和修改数据库记录的完整源程序代码:
using System ;
using System.Drawing ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data.OleDb ;
using System.Data ;
public class DataEdit : Form { private System.ComponentModel.Container components ;
private Button delete ;
private Button update ;
private Button lastrec ;
private Button nextrec ;
private Button previousrec ;
private Button firstrec ;
private TextBox t_bookstock ;
private TextBox t_bookprice ;
private TextBox t_bookauthor ;
private TextBox t_booktitle ;
private TextBox t_bookid ;
private Label l_bookstock ;
private Label l_bookprice ;
private Label l_bookauthor ;
private Label l_booktitle ;
private Label l_bookid ;
private Label label1 ;
private System.Data.DataSet myDataSet ;
private BindingManagerBase myBind ;
private bool isBound = false ;
//定义此变量,是判断组件是否已经绑定数据表中的字段

public DataEdit ( ) {
// 对窗体中所需要的内容进行初始化
InitializeComponent ( ) ;
//连接到一个数据库
GetConnected ( ) ;
}
//清除程序中用到的所有资源
public override void Dispose ( ) {
base.Dispose ( ) ;
components.Dispose ( ) ;
}
public void GetConnected ( )
{
try{
//创建一个 OleDbConnection对象
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
string strCom = " SELECT * FROM books " ;
//创建一个 DataSet对象
myDataSet = new DataSet ( ) ;
myConn.Open ( ) ;
OleDbDataAdapter myCommand = new OleDbDataAdapter ( strCom , myConn ) ;
myCommand.Fill ( myDataSet , "books" ) ;
myConn.Close ( ) ;
//判断数据字段是否绑定到 TextBoxes
if ( !isBound )
{
//以下是为显示数据记录而把数据表的某个字段绑定在不同的绑定到文本框"Text"属性上
t_bookid.DataBindings.Add ( "Text" , myDataSet , "books.bookid" ) ;
t_booktitle.DataBindings.Add ( "Text" , myDataSet , "books.booktitle" ) ;
t_bookauthor.DataBindings.Add ( "Text" , myDataSet , "books.bookauthor" ) ;
t_bookprice.DataBindings.Add ( "Text" , myDataSet , "books.bookprice" ) ;
t_bookstock.DataBindings.Add ( "Text" , myDataSet , "books.bookstock" ) ;
//设定 BindingManagerBase
//把对象DataSet和"books"数据表绑定到此myBind对象
myBind = this.BindingContext [ myDataSet , "books" ] ;
isBound = true ;
}
}
catch ( Exception e )
{
MessageBox.Show ( "连接数据库发生错误为:" + e.ToString ( ) , "错误!" ) ;
}
}
public static void Main ( ) {
Application.Run ( new DataEdit ( ) ) ;
}
private void InitializeComponent ( )
{
this.components = new System.ComponentModel.Container ( ) ;
this.t_bookid = new TextBox ( ) ;
this.previousrec = new Button ( ) ;
this.l_bookauthor = new Label ( ) ;
this.delete = new Button ( ) ;
this.t_booktitle = new TextBox ( ) ;
this.t_bookauthor = new TextBox ( ) ;
this.t_bookprice = new TextBox ( ) ;
this.l_bookprice = new Label ( ) ;
this.t_bookstock = new TextBox ( ) ;
this.l_bookstock = new Label ( ) ;
this.l_booktitle = new Label ( ) ;
this.update = new Button ( ) ;
this.nextrec = new Button ( ) ;
this.lastrec = new Button ( ) ;
this.firstrec = new Button ( ) ;
this.label1 = new Label ( ) ;
this.l_bookid = new Label ( ) ;
t_bookid.Location = new System.Drawing.Point ( 184 , 56 ) ;
t_bookid.Size = new System.Drawing.Size ( 80 , 20 ) ;

t_booktitle.Location = new System.Drawing.Point ( 184 , 108 ) ;
t_booktitle.Size = new System.Drawing.Size ( 176 , 20 ) ;

t_bookauthor.Location = new System.Drawing.Point ( 184 , 160 ) ;
t_bookauthor.Size = new System.Drawing.Size ( 128 , 20 ) ;

t_bookprice.Location = new System.Drawing.Point ( 184 , 212 ) ;
t_bookprice.Size = new System.Drawing.Size ( 80 , 20 ) ;

t_bookstock.Location = new System.Drawing.Point ( 184 , 264 ) ;
t_bookstock.Size = new System.Drawing.Size ( 80 , 20 ) ;
//以下是设定在程序中使用到的Label属性
l_bookid.Location = new System.Drawing.Point ( 24 , 56 ) ;
l_bookid.Text = "序 号:" ;
l_bookid.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_bookid.Font = new System.Drawing.Font ( "宋体" , 12f ) ;
l_bookid.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_booktitle.Location = new System.Drawing.Point ( 24 , 108 ) ;
l_booktitle.Text = "书 名:" ;
l_booktitle.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_booktitle.Font = new System.Drawing.Font ( "宋体" , 12f ) ;
l_booktitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookauthor.Location = new System.Drawing.Point ( 24 , 160 ) ;
l_bookauthor.Text = "作 者:";
l_bookauthor.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_bookauthor.Font = new System.Drawing.Font ( "宋体" , 12f ) ;
l_bookauthor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookprice.Location = new System.Drawing.Point ( 24 , 212 ) ;
l_bookprice.Text = "价 格:" ;
l_bookprice.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_bookprice.Font = new System.Drawing.Font ( "宋体" , 12f ) ;
l_bookprice.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;

l_bookstock.Location = new System.Drawing.Point ( 24 , 264 ) ;
l_bookstock.Text = "书 架 号:" ;
l_bookstock.Size = new System.Drawing.Size ( 142 , 20 ) ;
l_bookstock.Font = new System.Drawing.Font ( "宋体" , 12f ) ;
l_bookstock.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;

//以下设定程序中用到的功能按钮的属性及对应的事件
delete.Location = new System.Drawing.Point ( 104 , 352 ) ;
delete.ForeColor = System.Drawing.Color.Black ;
delete.Size = new System.Drawing.Size ( 80 , 24 ) ;
delete.Font = new System.Drawing.Font ( "宋体" , 9f ) ;
delete.Text = "删除记录" ;
delete.Click += new System.EventHandler ( GoDelete ) ;

update.Location = new System.Drawing.Point ( 204 , 352 ) ;
update.ForeColor = System.Drawing.Color.Black ;
update.Size = new System.Drawing.Size ( 80 , 24 ) ;
update.Font = new System.Drawing.Font ( "宋体" , 9f ) ;
update.Text = "修改记录" ;
update.Click += new System.EventHandler ( GoUpdate ) ;

firstrec.Location = new System.Drawing.Point ( 64 , 312 ) ;
firstrec.ForeColor = System.Drawing.Color.Black ;
firstrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
firstrec.Font = new System.Drawing.Font ( "宋体" , 9f ) ;
firstrec.Text = "首记录" ;
firstrec.Click += new System.EventHandler ( GoFirst ) ;

previousrec.Location = new System.Drawing.Point ( 136 , 312 ) ;
previousrec.ForeColor = System.Drawing.Color.Black ;
previousrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
previousrec.Font = new System.Drawing.Font ( "宋体" , 9f ) ;
previousrec.Text = "上一条" ;
previousrec.Click += new System.EventHandler ( GoPrevious ) ;

nextrec.Location = new System.Drawing.Point ( 208 , 312 ) ;
nextrec.ForeColor = System.Drawing.Color.Black ;
nextrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
nextrec.Font = new System.Drawing.Font ( "宋体" , 9f ) ;
nextrec.Text = "下一条" ;
nextrec.Click += new System.EventHandler ( GoNext ) ;

lastrec.Location = new System.Drawing.Point ( 280 , 312 ) ;
lastrec.ForeColor = System.Drawing.Color.Black ;
lastrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
lastrec.Font = new System.Drawing.Font ( "宋体" , 9f ) ;
lastrec.Text = "尾记录" ;
lastrec.Click += new System.EventHandler ( GoLast ) ;

label1.Location = new System.Drawing.Point ( 60 , 20 ) ;
label1.Text = "用Visual C#来修改和删除数据库中的记录" ;
label1.Size = new System.Drawing.Size ( 296 , 24 ) ;
label1.ForeColor = System.Drawing.SystemColors.Desktop ;
label1.Font = new System.Drawing.Font ( "宋体" , 14f ) ;
//设定程序的主窗体的属性
this.Text = "用Visual C#来修改和删除数据库中的记录!" ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;
this.FormBorderStyle = FormBorderStyle.FixedSingle ;
this.ClientSize = new System.Drawing.Size ( 394 , 425 ) ;
//在主窗体中加入组件
this.Controls.Add ( delete ) ;
this.Controls.Add ( update ) ;
this.Controls.Add ( lastrec ) ;
this.Controls.Add ( nextrec ) ;
this.Controls.Add ( previousrec ) ;
this.Controls.Add ( firstrec ) ;
this.Controls.Add ( t_bookstock ) ;
this.Controls.Add ( t_bookprice ) ;
this.Controls.Add ( t_bookauthor ) ;
this.Controls.Add ( t_booktitle ) ;
this.Controls.Add ( t_bookid ) ;
this.Controls.Add ( l_bookstock ) ;
this.Controls.Add ( l_bookprice ) ;
this.Controls.Add ( l_bookauthor ) ;
this.Controls.Add ( l_booktitle ) ;
this.Controls.Add ( l_bookid ) ;
this.Controls.Add ( label1 ) ;

}
//"删除记录"对应的事件
protected void GoDelete ( object sender, System.EventArgs e )
{
try{
//连接到一个数据库
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;
string strDele = "DELETE FROM books WHERE bookid= " + t_bookid.Text ;
OleDbCommand myCommand = new OleDbCommand ( strDele , myConn ) ;
//从数据库中删除指定记录
myCommand.ExecuteNonQuery ( ) ;
//从DataSet中删除指定记录
myDataSet.Tables [ "books" ] . Rows [ myBind.Position ] . Delete ( ) ;
myDataSet.Tables [ "books" ] . AcceptChanges ( ) ;
myConn.Close ( ) ;
}
catch ( Exception ed )
{
MessageBox.Show ( "删除记录错误信息: " + ed.ToString ( ) , "错误!" ) ;
}
}
//"修改记录"按钮对应的事件
protected void GoUpdate ( object sender , System.EventArgs e )
{
int i = myBind.Position ;
try{
//连接到一个数据库
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;

//从数据库中修改指定记录
string strUpdt = " UPDATE books SET booktitle = '"
+ t_booktitle.Text + "' , bookauthor = '"
+ t_bookauthor.Text + "' , bookprice = "
+ t_bookprice.Text + " , bookstock = "
+ t_bookstock.Text + " WHERE bookid = " + t_bookid.Text ;

OleDbCommand myCommand = new OleDbCommand ( strUpdt , myConn ) ;
myCommand.ExecuteNonQuery ( ) ;
myConn.Close ( ) ;
}
catch ( Exception ed )
{
MessageBox.Show ( "修改指定记录错误: " + ed.ToString ( ) , "错误!" ) ;
}
myBind.Position = i ;
}
//"尾记录"按钮对应的事件
protected void GoLast ( object sender , System.EventArgs e )
{
myBind.Position = myBind.Count - 1 ;
}
//"下一条"按钮对应的事件
protected void GoNext ( object sender , System.EventArgs e )
{
if ( myBind.Position == myBind.Count - 1 )
MessageBox.Show ( "已经到尾记录!" ) ;
else
myBind.Position += 1 ;
}
//"上一条"按钮对应的事件
protected void GoPrevious ( object sender , System.EventArgs e )
{
if ( myBind.Position == 0 )
MessageBox.Show ( "已经到首记录!" ) ;
else
myBind.Position -= 1 ;
}
//"首记录"按钮对应的事件
protected void GoFirst ( object sender , System.EventArgs e )
{
myBind.Position = 0 ;
}
}


四.编译源程序代码,生成执行文件:
得到了Data.cs源程序代码以后,经过下面编译命令编译成功后,即可得到执行文件data.exe:
csc /t:winexe /r:system.windows.forms.dll /r:system.data.dll data.cs

五.总结:
本文主要介绍了如何用Visual C#来删除和修改记录。以及在处理这些操作的时候,应该注意的一些重要问题及处理的方法。如果你的机器已经满足本文要求的运行环境,那么在生成的执行文件目录中建立一个sample.mdb数据库,在数据库中创建一个books数据表,数据表的结构可按照本文上面提供的结构来建立,在这一切都完毕后,就可以运行程序,享受Visual C#给我们带来的数据操作的快感了。 
C/C++ VS2019连接MySQL数据库 - 增删改查(详细步骤) 找到自己安装MySQL的路径,确保有include和lib两个文件夹打开创建的Visual Studio项目,切换x64平台注意:如果你的项目中没有x64平台,请严格按照下面图片的步骤进行操作a. 点击下拉框,点击配置管理器b.在弹出的配置管理器页面,创建一个x64平台,并确定c.将两个平台都切换至x64,关闭即可关闭后,也许你会发现自己的项目中已经没有生成或者重写生成的功能,这问题不大,不影响正常编译运行代码!点击项目,属性。 阅读详情

相关推荐

增加或删除事件处理程序

方法中都作为第一个参数传递。它与第一种方法不同,第一种方法需要在事件名称前加上。不推荐使用这种方法,因为我们只能为每个事件附加一个处理程序。使用addEventListener方法。您可以通过属性设置事件处理程序,其中。使用on属性(不推荐)事件的任何现有处理程序。例如,设置属性将覆盖。请注意,事件名称在和。...

liuhao9999的博客 750

用Visual C#来修改和删除数据库记录

在以前的一篇文章《Visual C#中轻松浏览数据库记录》中,我们介绍了用Visual C#如何把数据表中的字段值绑定到文本框的属性上和如何操作数据记录指针,随意浏览数据表中的记录。本文就接着上一篇的内容,来介绍用Visual C#如何来修改和删除数据记录。 一.程序设计和运行的环境设置: 视窗2000服务器版 Microsoft Access Data Component 2.6 以

平凡的心 3588

ESP32之 ESP-IDF + Clion 开发环境搭建(二)—— Linux版

本文介绍了 Linux 下,使用Clion IDE 用官方 ESP-IDF 开发包进行 ESP32 开发的环境搭建

Augtons 的博客 6113

移动端如何使用 vConsole 调试

前言:移动端(如手机、iPad)无法打开控制台像pc端一样使用console.log,使用chrome的inspect 也蛮麻烦的,借助vConsole就会变得很方便。方法二:下载源码文件:下载找到dist/vconsole.min.js 这个文件放到项目的static静态资源下面,然后在main.js中import进来。使用:VConsole 只是 vConsole 的原型,而非一个已实例化的对象。方法三:使用 CDN 直接插入到 HTML。方法一:使用 npm(推荐)...

lemon今天学习了吗?的博客 2798

WPF+Prism+LiveCharts+materialdesignin 搭建WPF开发框架

例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。提示:以下是本篇文章正文内容。

T_Tboy的博客 3062

c语言压力变送器程序设计,基于单片机的压力变送器设计

基于单片机的压力变送器设计(任务书,开题报告,外文翻译,论文15000字,代码)摘要随着工业化水平的不断提高,新型智能仪表在工业生产过程中运用也越来越广泛,同时对输出数据的准确检测和处理也变得至关重要。生产过程的运行和设备安全是极其重要的,那么如何实现对其精确的检测呢?众所周知,在工业生产过程中有一个很重要参数——压力,显然这个参数是一个必不可少的条件。故而,研究智能压力变松器系统对工业生产有着不...

weixin_33681561的博客 1973

用Visual C#来修改和删除数据库记录【转载】

一.程序设计和运行的环境设置:(1).视窗2000服务器版(2).Microsoft Access Data Component 2.6 以上版本 ( MADC 2.6 )(3).本文程序使用的数据库的介绍:为了方便起见,在选用数据库方面选用了本地数据库Access 2000,当然你也可以选用其他类型的数据库,只需要更改文章后面的程序源代码中数据库的引擎,并更改对应的...

dieshiji0937的博客 303

手把手教你用Trae配置Python开发环境(含Claude 3.5代码生成实战)

本文详细介绍了如何使用字节跳动推出的Trae智能开发环境配置Python开发环境,并实战演示了Claude 3.5代码生成功能。从环境准备到项目初始化,再到AI辅助编码和调试优化,全面展示了Trae在提升开发效率方面的强大能力,特别适合Python开发者快速搭建项目和解决复杂问题。

weixin_28309571的博客 988

c#数据库编程

<br />针对数据库编程始终是程序设计语言的一个重要方面的内容,也是一个难点。数据库编程的内容十分丰富,但最为基本编程的也就是那么几点,譬如:连接数据库、得到需要的数据和针对数据记录的浏览、删除、修改、插入等操作。其中又以后面针对数据记录的数据操作为重点。本文就来着重探讨一下Visual C#数据库基本编程,即:如何浏览记录、修改记录、删除记录和插入记录。 <br /> <br />  一.程序设计和运行的环境设置: <br /> <br />  (1).视窗2000服务器版 <br /> <br /> 

291

iPhone用户必看:TrollStore巨魔商店在线安装保姆级教程(iOS 14-16.6.1适用)

本文为iOS 14至16.6.1系统的iPhone用户提供了一份详细的TrollStore(巨魔商店)在线安装教程。文章从核心原理、安装前准备讲起,逐步详解了通过Safari浏览器获取安装器、信任企业证书、部署TrollStore及关键后置配置的全过程,并附带了常见问题排错指南,帮助用户安全、高效地实现无需越狱安装第三方应用。

h0i1j2k3l的博客 2120

整合Springboot+MybatisPlus+达梦数据库

整合Springboot+MybatisPlus+达梦数据库,以及一些坑

波波的博客 6685

C#数据库編程2

四.插入数据记录:   对数据库进行插入记录操作和删除记录操作基本的思路是一致的,就是通过ADO.NET首先插入数据记录到数据库,然后对"DataSet"对象进行必要的修改。下列代码就是以Access 2000数据库为模型修改当前记录的代码: protected void Update_record ( object sender , System.EventArgs e ) { int

zzychb的专栏 1154

基于ArduPilot的旋翼式无人机飞行器开发系列(二,学习路线)

一,热爱 作为一名耿直的技术男,在这里我只想说一句,热爱是可持续学习的第一要素,也只有热爱才能让你坚持到最后。 至于最后能得到什么,只有你自己知道。常说书中自有颜如玉,书中自有黄金屋。如果你是为了颜如玉,我相信大多数颜如玉做不了你的红颜知己。如果是为了黄金屋,当你持续投入时间和金钱却看不到回报的时候,相信退堂鼓早已隆隆作响。 我给自己的信条就是为当下努力工作,为将来持续学习。当前飞控行业并没有爆发,如果想赚块钱,去互联网汽车,去VR/AR吧,去元宇宙吧。 那么我热爱...

从0到1,突破自己 1684

实战VisualC#数据库编程

[编者的话:]关于数据库编程,微软提供了一个统一的数据对象访问模型,在Visual Studio6.0中称为ADO,在.NET中则统一为ADO.NET,掌握ADO.NET就等于掌握了数据库编程的核心,因此有必要首先复习一下以前发表的《ADO.NET完全攻略》。  针对数据库编程始终是程序设计语言的一个重要方面的内容,也是一个难点。数据库编程的内容十分丰富,但最为基本编程的也就是那么几点,譬如:

早晨的阳光的专栏 965

RK3588 平台部署实战:OpenCV + LibTorch + FFmpeg 环境搭建与深度学习推理全流程解析

现在,你已经掌握了在RK3588上搭建OpenCV+LibTorch+FFmpeg环境的完整流程,也完成了深度学习模型的部署测试。不妨从一个具体的应用场景入手(如检测自家宠物的品种),亲手打造属于你的第一个边缘智能应用——当你看到模型在RK3588上精准输出结果时,你会发现:嵌入式深度学习的门槛,其实并没有想象中那么高。这些依赖是编译OpenCV、FFmpeg的基础,安装过程中若提示权限不足,可在命令前加。若能输出预测的类别索引,则说明环境搭建成功,模型推理流程通畅。文件,实现模型加载、图像预处理与推理。

FJN110的博客 548

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

VC#数据库编程1

 针对数据库编程始终是程序设计语言的一个重要方面的内容,也是一个难点。数据库编程的内容十分丰富,但最为基本编程的也就是那么几点,譬如:连接数据库、得到需要的数据和针对数据记录的浏览、删除、修改、插入等操作。其中又以后面针对数据记录的数据操作为重点。本文就来着重探讨一下Visual C#数据库基本编程,即:如何浏览记录、修改记录、删除记录和插入记录。    一.程序设计和运行的环境设置:

zzychb的专栏 1249

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

详解 Visual C# 数据库编程

关于数据库编程,微软提供了一个统一的数据对象访问模型,在Visual Studio6.0中称为ADO,在.NET中则统一为ADO.NET,掌握ADO.NET就等于掌握了数据库编程的核心。 &lt;script id="ad_text_pcjob" src="http://www.pconline.com.cn/script/ad_text_pcjob.js"&gt;&lt;/script&g...

GOBY 栏目 710

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Visual C#数据库编程--入门

关于数据库编程,微软提供了一个统一的数据对象访问模型,在Visual Studio6.0中称为ADO,在.NET中则统一为ADO.NET,掌握ADO.NET就等于掌握了数据库编程的核心。   针对数据库编程始终是程序设计语言的一个重要方面的内容,也是一个难点。数据库编程的内容十分丰富,但最为基本编程的也就是那么几点,譬如:连接数据 库、得到需要的数据和针对数据记录的浏览、删除、修改、插入等操作。其...

weixin_30436101的博客 230

祥解Visual C#数据库编程

关于数据库编程,微软提供了一个统一的数据对象访问模型,在Visual Studio6.0中称为ADO,在.NET中则统一为ADO.NET,掌握ADO.NET就等于掌握了数据库编程的核心。  针对数据库编程始终是程序设计语言的一个重要方面的内容,也是一个难点。数据库编程的内容十分丰富,但最为基本编程的也就是那么几点,譬如:连接数据库、得到需要的数据和针对数据记录的浏览、删除、修改、插入等操作。其中又

菜刀王六的专栏 2385
上一篇: 通过datatable获得表的主键
下一篇: 用VisualC#来增加数据记录
daybreak1978
博客等级 码龄22年 0粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值