⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 12655.htm

📁 一本很基础的SQL讲解
💻 HTM
字号:
<link href="./dzs_cs.css" rel="stylesheet" type="text/css" /><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">      <tr>        <td>&nbsp;</td>      </tr>      <tr>        <td height="24" align="center" valign="bottom" class="d_font3">连接SQL Server的公共类VB.NET</td>      </tr>      <tr>        <td height="3" bgcolor="#E3E3E3"></td>      </tr>      <tr>        <td>&nbsp;</td>      </tr>      <tr>        <td class="d_font4"> <P>*************************************************************************<BR>'//开始日期:2002年5月27日 </P>
<P>'//结束日期:2002年5月27日 </P>
<P>'***********************************************************************</P>
<P>Option Explicit On </P>
<P>'Option Strict On </P>
<P>'//***********************************************************************<BR>Imports System.Data.SqlClient </P>
<P>'//*************************************************************************</P>
<P>'//Begin defined namespace </P>
<P>Namespace Sunerp.CommClass.Comm </P>
<P>'//Defined Structure PublicApplicationVal </P>
<P>'//Structure descriptoin </P>
<P>'//本结构存取 数据库服务器名(Dbserver)、数据库用户ID(UserId)、 </P>
<P>'//数据库用户密码(UserPWD)、数据库名(Dbase),为联接数据库提供参数。 </P>
<P>'//为了满足某些简单查询的需要,提供了扩展的变量 常用表名(DBTable)、 </P>
<P>'//查询字段名(QueryFieldName)、查询字段值 </P>
<P>'//Begin define Structure PublicApplicationVal </P>
<P>Public Structure PublicApplicationVal </P>
<P>' Public Dbserver, UserId UserPWD Dbase DBTable Account. </P>
<P>Public Dbserver As String </P>
<P>Public UserId As String </P>
<P>Public UserPWD As String </P>
<P>Public Dbase As String </P>
<P>Public DBTable As String </P>
<P>Public QueryFieldVale As String </P>
<P>Public QueryFieldName As String </P>
<P>End Structure </P>
<P>'//End define Structure PublicApplicationVal </P>
<P>'//********************************************************************</P>
<P>'//Begin defined Class </P>
<P>Public Class DBaseBindComm </P>
<P>''*****************************************************************</P>
<P>''//**定义连接SQL Server Database的通用函数**// </P>
<P>'//本函数创建一个到指定数据库的连接对象 SqlConnection </P>
<P>'//本函数有1个参数,IPublicApplication 为公共数据结构 PublicApplicationVal, </P>
<P><BR>'//Begin define Function LinkedSqlServer </P>
<P>Public Overloads Function LinkedSqlServer() As System.Data.SqlClient.SqlConnection </P>
<P>Dim strconn As String </P>
<P>Dim conn As New SqlConnection() </P>
<P>strconn = "server=" & "erp" & _ </P>
<P>";user id=" & "erpsa" & _ </P>
<P>";password=" & "erpsa" & _ </P>
<P>";database=" & "erpdata" & ";" </P>
<P>Try </P>
<P>conn = New SqlConnection(strconn) </P>
<P>conn.Open() </P>
<P>StateVal = True </P>
<P>LinkedSqlServer = conn </P>
<P>Catch ex As Exception </P>
<P>' MsgBox(ex.ToString) </P>
<P>StateVal = False </P>
<P>LinkedSqlServer = Nothing </P>
<P>Exit Function </P>
<P>End Try </P>
<P>End Function </P>
<P></P>
<P>''End defined LinkedSqlServer </P>
<P>''*********************************************************************** </P>
<P>''//**定义连接SQL Server Database的通用函数**// </P>
<P>'//本函数创建一个到指定数据库的连接对象 SqlConnection </P>
<P>'//本函数有1个参数,IPublicApplication 为公共数据结构 PublicApplicationVal, </P>
<P>'//Begin define Function LinkedSqlServer </P>
<P>Public Overloads Function LinkedSqlServer( _ </P>
<P>ByVal IPublicApplication As PublicApplicationVal) _ </P>
<P>As System.Data.SqlClient.SqlConnection </P>
<P>Dim strconn As String </P>
<P>Dim conn As New SqlConnection() </P>
<P>strconn = "server=" & IPublicApplication.Dbserver & _ </P>
<P>";user id=" & IPublicApplication.UserId & _ </P>
<P>";password=" & IPublicApplication.UserPWD & _ </P>
<P>";database=" & IPublicApplication.Dbase & ";" </P>
<P>Try </P>
<P>conn = New SqlConnection(strconn) </P>
<P>conn.Open() </P>
<P>StateVal = True </P>
<P>LinkedSqlServer = conn </P>
<P>Catch ex As Exception </P>
<P>' MsgBox(ex.ToString) </P>
<P>StateVal = False </P>
<P>LinkedSqlServer = Nothing </P>
<P>Exit Function </P>
<P>End Try </P>
<P>End Function </P>
<P>''End defined LinkedSqlServer </P>
<P>''**************************************************************</P>
<P></P>
<P>''定义类DBaseBindComm的ReadOnly属性State(创建连接的状态) </P>
<P>''True(创建成功),False(创建失败) </P>
<P>Private StateVal As Boolean </P>
<P>Public ReadOnly Property State() As Boolean </P>
<P>Get </P>
<P>Return StateVal </P>
<P>End Get </P>
<P>End Property </P>
<P><BR>End Class </P>
<P><BR>Public Class OrganComm </P>
<P><BR>'//Defined Structure PublicOrganIDStructure </P>
<P>'//Structure descriptoin </P>
<P>'//本结构存取 企业组织机构Id </P>
<P>'//顶层(DeptTopID)、一级(DeptMidId),二级ID(DeptLowId) </P>
<P>'//Begin define Structure PublicOrganIDStructure </P>
<P>Public Structure PublicOrganIDStructure </P>
<P>Public DeptTopID As String </P>
<P>Public DeptMidId As String </P>
<P>Public DeptLowId As String </P>
<P>End Structure </P>
<P>'//End define Structure PublicOrganIDStructure </P>
<P>'//******************************************************************</P>
<P>''//**定义连接SQL Server Database的通用函数**// </P>
<P>'//本函数创建一个到指定数据库的连接对象 SqlConnection </P>
<P>'//本函数有1个参数,IPublicApplication 为公共数据结构 PublicApplicationVal, </P>
<P>'//Begin define Function IParseDeptOrgid </P>
<P>Public Function IParseDeptOrgid(ByVal IDeptOrgid As String) As PublicOrganIDStructure </P>
<P>Dim OrganID As New PublicOrganIDStructure() </P>
<P>Dim Orgid As String </P>
<P><BR>IDeptOrgid = Trim(IDeptOrgid) </P>
<P>Orgid = Microsoft.VisualBasic.Left(Trim(IDeptOrgid), 12) </P>
<P><BR>OrganID.DeptTopID = Microsoft.VisualBasic.Left(Orgid, 6) </P>
<P>OrganID.DeptMidId = Microsoft.VisualBasic.Right(Orgid, 6) </P>
<P>OrganID.DeptLowId = Microsoft.VisualBasic.Right(IDeptOrgid, 6) </P>
<P>IParseDeptOrgid = OrganID </P>
<P>End Function </P>
<P>'//End define Function IParseDeptOrgid </P>
<P>End Class </P>
<P></P>
<P>End Namespace </P>
<P>'*******************************************************************************</P> </td>      </tr>      <tr>        <td class="d_font4">&nbsp;</td>      </tr>    </table>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -