16,555
社区成员
发帖
与我相关
我的任务
分享
Private iobj_connection As OleDb.OleDbConnection
Private iobj_command As OleDb.OleDbCommand
Private iobj_adapter As OleDb.OleDbDataAdapter
iobj_connection=new OleDbConnection("聯接字符串")
iobj_adapter =new OleDbDataAdapter("sql",iobj_connection)
iobj_command =new OleDbCommand("sql",iobj_connection)
'''select用iobj_adapter.fill方法
'''update,delete,insert用iobj_command.ExecuteNonQuery()方法
Public Shared connstr As String = "Server=" & _
sqlservername & ";packet size=4096;Database=" & sqldatabase & _
";User ID=" & sqlusername & ";Password=" & sqlpassword & ";Trusted_Connection=False"
Public Shared Conn As New SqlConnection(connstr)
DIM EchoDS as DATASET
Public Shared Function sqlread(ByVal sql As String, ByVal tablename As String)
Try
Dim sqlcmd As New SqlDataAdapter(sql, Conn)
sqlcmd.Fill(EchoDS, tablename)
Catch ex As Exception
EchoDS.Tables(tablename).Reset()
Return Nothing
End Try
Return Nothing
End Function
Public Shared Function sqlrun(ByVal sql As String, ByVal okmsg As String, ByVal errmsg As String)
Try
Conn.Open()
Dim sqlcmd As New SqlCommand(sql, Conn)
sqlcmd.ExecuteNonQuery()
Conn.Close()
If okmsg <> "" Then
MsgBox(okmsg, MsgBoxStyle.Information, "数据操作成功!")
End If
Catch ex As Exception
If errmsg <> "" Then
MsgBox(errmsg + " " + ex.Message, MsgBoxStyle.Exclamation, "数据操作失败!")
Else
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "数据操作失败!")
End If
Return Nothing
End Try
Return Nothing
End Function