VB.NET操作SQL Server完全模块

server

Module ModSql

Function GetIntByStr(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where " & ParaName & "='" & ParaValue & "'"

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), 0, sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetIntByInt(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As Integer) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where " & ParaName & "=" & ParaValue & ""

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), 0, sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetStrByStr(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As String) As String

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where " & ParaName & "='" & ParaValue & "'"

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As String = ""

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), "", sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return Trim(rowsAffected)

End Function

Function GetStrByInt(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As Integer) As String

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where " & ParaName & "=" & ParaValue & ""

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As String = ""

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), "", sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return Trim(rowsAffected)

End Function

Function GetBitByStr(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As String) As Boolean

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where " & ParaName & "='" & ParaValue & "'"

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Boolean = False

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), False, sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetBitByInt(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As Integer) As Boolean

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where " & ParaName & "=" & ParaValue & ""

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Boolean = False

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), False, sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetDateByInt(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As Integer) As DateTime

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where " & ParaName & "=" & ParaValue & ""

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As DateTime

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), DateAdd(DateInterval.Year, -100, Date.Now), sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetDateByStr(ByVal FieldName As String, ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As String) As DateTime

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "select Top 1 " & FieldName & " from " & TableName & " where " & ParaName & "='" & ParaValue & "'"

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As DateTime

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), DateAdd(DateInterval.Year, -100, Date.Now), sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function DelByInt(ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As Integer) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "DELETE FROM " & TableName & " WHERE " & ParaName & " =" & ParaValue

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function DelByStr(ByVal TableName As String, ByVal ParaName As String, ByVal ParaValue As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "DELETE FROM " & TableName & " WHERE " & ParaName & "='" & ParaValue & "'"

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function DelBySQL(ByVal StrSQL As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = StrSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function UpdateBitBySQL(ByVal TableName As String, ByVal DataFieldName As String, ByVal DataFieldValue As Boolean, ByVal ParaSQL As String) As String

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "UPDATE " & TableName & " SET " & DataFieldName & " = " & IIf(DataFieldValue = True, 1, 0) & " WHERE " & ParaSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

sqlConnection.Open()

Try

sqlCommand.ExecuteNonQuery()

Return ""

Catch ex As Exception

Return ex.Message

Finally

sqlConnection.Close()

End Try

End Function

Function UpdateStrByInt(ByVal TableName As String, ByVal DataFieldName As String, ByVal DataFieldValue As String, ByVal Para As String, ByVal ParaValue As Integer) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "UPDATE " & TableName & " SET " & DataFieldName & " = '" & DataFieldValue & "' WHERE " & Para & " = " & ParaValue

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function UpdateStrByStr(ByVal TableName As String, ByVal DataFieldName As String, ByVal DataFieldValue As String, ByVal Para As String, ByVal ParaValue As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "UPDATE " & TableName & " SET " & DataFieldName & " = '" & DataFieldValue & "' WHERE " & Para & " = '" & ParaValue & "'"

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function UpdateIntByInt(ByVal TableName As String, ByVal DataFieldName As String, ByVal DataFieldValue As Integer, ByVal Para As String, ByVal ParaValue As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "UPDATE " & TableName & " SET " & DataFieldName & " = " & DataFieldValue & " WHERE " & Para & " = " & ParaValue

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function UpdateIntByStr(ByVal TableName As String, ByVal DataFieldName As String, ByVal DataFieldValue As Integer, ByVal Para As String, ByVal ParaValue As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "UPDATE " & TableName & " SET " & DataFieldName & " = " & DataFieldValue & " WHERE " & Para & " = '" & ParaValue & "'"

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function UpdateIntBySQL(ByVal TableName As String, ByVal DataFieldName As String, ByVal DataFieldValue As Integer, ByVal ParaSQL As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "UPDATE " & TableName & " SET " & DataFieldName & " = " & DataFieldValue & " WHERE " & ParaSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function UpdateStrBySQL(ByVal TableName As String, ByVal DataFieldName As String, ByVal DataFieldValue As String, ByVal ParaSQL As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "UPDATE " & TableName & " SET " & DataFieldName & " = '" & DataFieldValue & "' WHERE " & ParaSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function UpdateBySQL(ByVal TableName As String, ByVal SetSQL As String, ByVal ParaSQL As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "UPDATE " & TableName & " SET " & SetSQL & " WHERE " & ParaSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteNonQuery

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetDataTableByFormat(ByVal vRecordNumber As Integer, ByVal ItemSQL As String, ByVal TableName As String, ByVal ParaSQL As String) As System.Data.DataTable

Dim RecordNumber As String

If vRecordNumber = 0 Then

RecordNumber = ""

Else

RecordNumber = "TOP " & vRecordNumber

End If

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "SELECT " & RecordNumber & " " & ItemSQL & " FROM " & TableName & " where " & ParaSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(sqlCommand)

Dim dataSet As System.Data.DataSet = New System.Data.DataSet

Try

dataAdapter.Fill(dataSet)

Return dataSet.Tables(0)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

End Function

Function GetDataTableBySQL(ByVal SuperSQL As String) As System.Data.DataTable

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(SuperSQL, sqlConnection)

Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(sqlCommand)

Dim dataSet As System.Data.DataSet = New System.Data.DataSet

Try

dataAdapter.Fill(dataSet)

Return dataSet.Tables(0)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

End Function

Function GetMaxField(ByVal TableName As String, ByVal FieldName As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "SELECT MAX(" & FieldName & ") AS MaxField FROM " & TableName

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), 0, sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetMinField(ByVal TableName As String, ByVal FieldName As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "SELECT Min(" & FieldName & ") AS MaxField FROM " & TableName

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer = 0

sqlConnection.Open()

Try

rowsAffected = IIf(IsDBNull(sqlCommand.ExecuteScalar), 0, sqlCommand.ExecuteScalar)

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetFieldCount(ByVal TableName As String, ByVal ParaSQL As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "SELECT COUNT(*) AS FieldCount FROM " & TableName & " where " & ParaSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteScalar

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetFieldSumByInt(ByVal TableName As String, ByVal FieldName As String, ByVal ParaSQL As String) As Integer

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "SELECT isnull(sum(" & FieldName & "),0) AS CountNumber FROM " & TableName & " where " & ParaSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Integer

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteScalar

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function GetFieldSumByDec(ByVal TableName As String, ByVal FieldName As String, ByVal ParaSQL As String) As Decimal

Dim sqlConnection As New SqlClient.SqlConnection(GetConn)

Dim queryString As String = "SELECT isnull(sum(" & FieldName & "),0) AS CountNumber FROM " & TableName & " where " & ParaSQL

Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)

Dim rowsAffected As Decimal

sqlConnection.Open()

Try

rowsAffected = sqlCommand.ExecuteScalar

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

Finally

sqlConnection.Close()

End Try

Return rowsAffected

End Function

Function ChgFieldByLeftWord(ByVal TableName As String, ByVal FieldName As String, ByVal ParaWord As String, ByVal NewWord As String) As Integer

Try

Return UpdateBySQL(TableName, FieldName & "='" & NewWord & "'+right(" & FieldName & ",len(" & FieldName & ")-" & Len(ParaWord) & ")", "Len(" & FieldName & ")>=" & Len(ParaWord) & " and left(" & FieldName & "," & Len(ParaWord) & ")='" & ParaWord & "'")

Catch ex As Exception

Throw New NotSupportedException(ex.Message)

End Try

End Function

'数据库连接串

Private Function GetConn() As String

Return "server=localhost;database=pubs;uid=sa;pwd="

End Function

End Module

时间: 2025-01-28 10:47:10

VB.NET操作SQL Server完全模块的相关文章

VB.NET操作 SQL SERVER的 二进制数据

server|二进制|数据 在VB时期, 向SQL SERVER 中插入二进制数据, 是通过 ADODB.STREAM 实现, 在.NET中, 对 "流"格式的操作更加强大而简单,本篇演示向SQL SERVER 中插入数据并读出的功能. 在窗体上添加一个 OPENFILEDIALOG 控件, 两个PICTUREBOX, 代码如下:-------------------------------------------------------------------------------

操作 SQL Server Mobile 2005 数据库的常用 C# 代码

server|sql|数据|数据库 整理几段操作 SQL Server Mobile 数据库的常用 C# 代码,供刚刚接触 SQL Server Mobile 开发的朋友参考. 1. 创建数据库// 创建数据库File.Delete("Test.sdf");SqlCeEngine engine = new SqlCeEngine(    "Data Source='Test.sdf';LCID=1033;Password=\"s$;2'!dS64\";En

Visual C#中动态操作SQL Server数据库

在编写数据库应用程序的时候,我们可以通过SQL语句来动态创建.修改数据库以及其中的对象.本文我就向大家介绍如何运用Visual C#来动态操作SQL Server数据库,其中包括如何创建一个SQL Server数据库以及如何创建其中的表.存储过程.视图.索引之类的数据库对象.本文还介绍了如何动态地修改表的模式,如何从表.存储过程以及视图中读取数据并显示在应用程序的数据库控件中. 我们知道SQL语句在操作数据库时运用得最多的是Select.Insert.Update和Delete等对于数据的操作,

Vb.net向sql server数据库中保存图片(一)

server|数据|数据库 预备知识:STREAM.ADO.NET 微软的SQL SERVER数据库的Image.text等字段都属于二进制的大对象.这些对象的存取和其他轻型对象略有不同.比如,我们打开一个数据表的时候,普通类型的字段都可以看见,而Image类型的字段却不行,只能通过编程的方法来读取.这篇资料就是介绍怎样用vb.NET来向sql server数据库中存放图片,怎样从数据库中取出图片浏览.我在这里也费了老大的精力,主要是为了答复一个同学的提问.(他刨根问底式的学习方式,把我急出一身

VC操作SQL Server主从表

工作之余,用VC作了一个小程序,是VC+SQL server模式的,程式内容比较简单,主要设及以下内容: 窗口如何分割: 多视图之间如何通信: 列表视图的操作及事件处理: 树形控件的操作及事件处理,利用递归根据数据库动态生成目录: 实现主从表的显示 以下对程序细节稍作一下说明: 一.窗口如何分割 切分窗口既适用于SDI应用程序,也适宜于MDI应用程序.它通常驻是以类 CSplitterWnd来表示,对 Windows 来说,CSplitterWnd 是一个真正的窗口,它完全占用框架窗口的客户区域

VB/ASP 调用 SQL Server 的存储过程

server|存储过程 昨天有位久未谋面的老同学,突然问起如何在VB中调用SQL的存储过程.当时因为手上没有资料,机器上也没装SQL,随即发了早年写的一段ASP代码,也不知道行不行.抱着负责任的态度,刚好又有点空闲,便做了个测试:(说来惭愧,N久没用VB了,居然不知道怎么加入ADODB类型库了,就填加了一个ADODC控件,汗颜~```) Private Sub ExampleButton_Click()Dim sqlConn As New ADODB.ConnectionDim sqlCmd A

Java操作SQL Server数据库

//首先导入sql server2008的jar包:sqljdbc4.jar,注意在一般的电脑上即使做了这样的操作仍然是吧不能连接上SQL Server 2008的,如果想连上SQL SQLSERVER2008还要做一下配置:请看博文:http://hi.baidu.com/1032610746/item/a1a84d086a9225e43599023f    和   http://hi.baidu.com/1032610746/item/41091f51549dfdd3d48bac36,如果想

asp.net(vb.net)连接sql server 2000数据库的连接模块(module)

asp.net|server|数据|数据库 Module MdlCommon Public txtSQL As String '存放SQL语句 Public DBSet As DataSet '查询得到的记录集 Public ErrorMsg As String '存放错误信息 Public Function ExecuteSQL(ByVal strSQL As String, ByRef errMsg As String) As DataSet Dim cnn As SqlClient.Sql

在ASP.NET中操作SQL Server的小技巧

asp.net|server|sql|技巧 1.给数据库语句参数传递 向数据库操作语句传递参数可以通过存储过程实现,这里给出另外两种简便易捷的方法: 可以在C#中通过字符串操作将参数直接传入SQL语句变量中,例如: string s="Davolio": string sql= "select * from employees where LastName="+"'"+s+"'" 相当于写入SQL语句: select * fr