连接数据库;引用命名空间:代码如下:ImportsSystem.Data.OleDb定义数据函数类型:DimsqlstrAsString='SQL命令语句DimpathAsString=path=Application.StartupPath&\DATE\Database2.mdb获取程序根目录Dimdat_ssAsString'=DateTime.Now.ToString(yyyy-MM-ddHH:mm:ss)获取系统时间及规定格式DimstrconnAsString'=(Provider=Microsoft.ACE.OLEDB.12.0;DataSource=&path)定义连接数据库驱动及数据库路径DimconnAsOleDb.OleDbConnection=NewOleDb.OleDbConnection(strconn)定义数据库连接类DimcommAsOleDb.OleDbCommand=NewOleDb.OleDbCommand(sqlstr,conn)定义SQL语言执行类DimDtAsDataSet定义数据表类读取数据sqlstr=SELECT*FROM实时数据WHERE工程编号='1'Try'SqlUse=NewOleDbDataAdapter(SELECT*FROM实时数据WHERE工程编号='&proidAs&',SqlCOM)comm=NewOleDb.OleDbCommand(sqlstr,conn)'DimSqlUseAsOleDbDataAdapter=NewOleDbDataAdapter(SELECT*FROM实时数据WHERE工程编号='1',conn)comm.Connection=connconn.Open()comm.CommandText()=sqlstrDimdrAsOleDbDataReader=comm.ExecuteReader()Label1.Text=dr.Read&&s(1)DoWhiledr.ReadDimnumAsInteger=1s(num)=dr.GetString(2)Loop'comm.ExecuteNonQuery()Label1.Text=dr.Read&&s(1)'MsgBox(保存成功!,MsgBoxStyle.Information,保存)CatchExAsExceptionMsgBox(Ex.Message,MsgBoxStyle.Critical,Error)EndTrycomm.Connection.Close()