vb.net增删改查 vb数据库增删改查

vb.net同时对两个ACCESS数据库进行增删改查。

见下面的代码,自己换成真实的数据库及表即可

创新互联是一家专注于做网站、成都网站建设与策划设计,西塞山网站建设哪家好?创新互联做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:西塞山等地区。西塞山做网站价格咨询:18980820575

Imports System.Data

Imports System.IO

Imports System.Data.OleDb

Module Module1

Public cn1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ACCESS数据库1.mdb") '定义连接1---这里请更改为实际数据库路径及名称 

Public cn2 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ACCESS数据库2.mdb") '定义连接2---这里请更改为实际数据库路径及名称 

Public DataBaseRST1 As Integer '用来返回数据库执行结果 

Public DataBaseRST2 As Integer '用来返回数据库执行结果

Public Function DataModify(ByVal str_cmd1 As String, ByVal str_cmd2 As String) As Boolean '进行数据库修改操作函数 

Dim cmdinsert1 As New OleDbCommand

Dim cmdinsert2 As New OleDbCommand

Try

cmdinsert1.CommandText = str_cmd1

cmdinsert2.CommandText = str_cmd2

cmdinsert1.Connection = cn1

cmdinsert2.Connection = cn2

If cn1.State = ConnectionState.Closed Then cn1.Open()

If cn2.State = ConnectionState.Closed Then cn2.Open()

DataBaseRST1 = cmdinsert1.ExecuteNonQuery() '用来返回执行的结果 

DataBaseRST2 = cmdinsert2.ExecuteNonQuery() '用来返回执行的结果 

cn1.Close()

cn2.Close()

Return True

Catch ex As Exception

MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Return False

End Try

End Function

End Module 

Public Class Form1 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

DataModify("insert into aa values ('1','2')", "insert into aa values ('1','2')") '调用方法

End Sub

End Class

vb.net如何用datagirdview控件显示并操作(增删改查)多张关联表?

数据库 用视图 把要显示的数据做成视图

datagridview显示视图

修改、删除、保存修改功能,直接更新到视图就行了

你好!有没有vb.net对SQL数据库进行增删改查的例子

一般都是vb.net传入参数 交给存储过程去做的 你是要在vb.net前台就执行的例子 还是想要调用存储过程的例子

前台的一般就是这样

Dim paras As New NameValueCollection

paras .Append("delete from T_AlarmConfig ")

paras .Append(" where AlarmConfigID=@AlarmConfigID")

调用存储过程的就是给写存储过程了,这是调用存储过程的例子,只能理解理解

''' summary

''' 删除数据

''' /summary

''' param name="procName"存储过程名/param

''' param name="paras"存储过程参数/param

''' remarks

''' 2006-5-29 zhuzh Created

''' /remarks

Public Sub DeleteData(ByVal procName As String, _

ByVal paras As NameValueCollection, _

Optional ByVal timeout As Integer = 30)

eventCount += 1

'存储过程参数名数组

Dim paraNames As String() = {}

'存储过程参数值数组

Dim paraValues As String() = {}

'传入的参数转化成数组

Me.ConvertNameValueCollection(paras, paraNames, paraValues, STATUS_UPDATE)

'判断系统类型调用相应模块的方法

If isWebSys Then

DeleteDelegateInstance = AddressOf webGw.ExecProc

Else

DeleteDelegateInstance = AddressOf AdoGw.ExecProc

End If

Dim ret As Integer = 0

Dim ds As New DataSet

'----guojun 2008-1-2 add-----

If timeout 60000 Then

timeout = 60000

End If

'--------防止超时异常--------

DeleteDelegateInstance.BeginInvoke(procName, ret, ds, paraNames, paraValues, timeout, _

AddressOf DataDeletedCallBack, Nothing)

End Sub

如何用vb.net查询、添加、删除、修改数据库(需要很详细的代码)?

sQueryString是SQL(增删查改)语句

public

Boolean

ExecSQL(string

sQueryString)

{

SqlConnection

con

=

new

SqlConnection(ConfigurationManager.AppSettings["conStr"]);

con.Open();

SqlCommand

dbCommand

=

new

SqlCommand(sQueryString,

con);

try

{

dbCommand.ExecuteNonQuery();

con.Close();

}

catch

{

con.Close();

return

false;

}

return

true;

}

}

建立一个类,明自己取,然后调用就是了

例如:

BC=NEW

类();

STRING

ist="INSERT

INTO

XX(1,2,3)VALUES(A,B,C)";

BC.ExecSQL(ist);

就可以了

求一个VB.net 增删改查实例 ,哪位大神有空帮我写一下或者有现成的给我一个,,我比较菜又比较急,在线等

Imports System.Data.OleDb

'Imports System.Data.OracleClient

Imports System.Data.SqlClient

'链接Oracle

'cn = New SqlConnection(""Data Source=TNS名称;Persist Security Info=True;User ID=用户名;Password=密码;" ")

'Imports System.Data.OracleClient

'Dim oOracleConn As OracleConnection = New OracleConnection()

'oOracleConn.ConnectionString = ""Data Source=MyOracleDB; User Id=username; Password=passwd; Integrated Security=no; "

'oOracleConn.Open()

'链接SQL Server

'cn = New SqlConnection("Data Source=.;Initial Catalog=Sales;Integrated Security=False;User ID=sa;Password=;")

'链接Access

'cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" db_path ";Persist Security Info=False")

Public Class Fun_DataBase

Dim cn As OleDbConnection

Dim cm As OleDbCommand

Dim da As OleDbDataAdapter

Dim ds As DataSet

Dim db_path As String = "D:\Documents\Visual Studio 2013\Projects\VBnet1\VBnet1\Resources\Database1.mdb"

Function Fun_sql1(Str_sql As String, V_调用来源 As String) '按指定sql,反馈1个查询值

Try

'Dim cn As New OleDbConnection("Data Source=.;Initial Catalog=Sales;Integrated Security=False;User ID=sa;Password=123456;")

'链接Access

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" db_path ";Persist Security Info=False")

cn.Open() 'sql语句执行前,必须打开连接

cm = New OleDbCommand(Str_sql, cn)

cm.ExecuteNonQuery()

Dim strValue As String = cm.ExecuteScalar.ToString

'MessageBox.Show(strValue)

Fun_sql1 = strValue

cn.Close()

Fun_sql1 = True

Catch ex As Exception

MessageBox.Show(V_调用来源 ":执行sql语句失败!" Str_sql)

Fun_sql1 = False

End Try

End Function

Function Fun_sqln(Str_sql As String, V_调用来源 As String) '按指定sql,反馈1行n列查询值

Try

'链接Access

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" db_path ";Persist Security Info=False")

cn.Open() 'sql语句执行前,必须打开连接

Dim cmd As New OleDbCommand("select * from grade", cn)

'Dim dr As SqlDataReader

Dim dr As OleDbDataReader

dr = cmd.ExecuteReader()

Dim strDisplay As String = ""

While dr.Read()

Fun_sqln = dr(0).ToString "|"

End While

cn.Close()

Fun_sqln = True

Catch ex As Exception

MessageBox.Show(V_调用来源 ":执行sql语句失败!" Str_sql)

Fun_sqln = False

End Try

'Dim s = Split(F.Fun_sqln("ef"), "|")

'Dim i As Integer

'i = UBound(s)

'For i = 0 To UBound(s)

' MessageBox.Show(s(i))

'Next

End Function

Public Function Fun_sql_exec(Str_sql As String, V_调用来源 As String) '执行指定sql,反馈T|F

Try

'链接Access

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" db_path ";Persist Security Info=False")

cn.Open() 'sql语句执行前,必须打开连接

cm = New OleDbCommand(Str_sql, cn)

cm.ExecuteNonQuery()

cn.Close()

Fun_sql_exec = True

Catch ex As Exception

MessageBox.Show(V_调用来源 ":执行sql语句失败!" Str_sql)

Fun_sql_exec = False

End Try

End Function


网页名称:vb.net增删改查 vb数据库增删改查
转载来源:http://myzitong.com/article/docpggd.html