数据采集 数据库 VB
connectionString="Data Source= 。;Initial Catalog=ERPDB;Persist Security Info=True;User ID=sa;Password= 123;max pool size=500" providerName="System。 Data。SqlClient" />SQL数据库连接 ''' ''' 以写文件的方式把DataTable数据导出到Excel ''' ''' ''' Public Sub WriteExcel(ByVal tableName As Stri...全部
connectionString="Data Source= 。;Initial Catalog=ERPDB;Persist Security Info=True;User ID=sa;Password= 123;max pool size=500" providerName="System。
Data。SqlClient" />SQL数据库连接 ''' ''' 以写文件的方式把DataTable数据导出到Excel ''' ''' ''' Public Sub WriteExcel(ByVal tableName As String) Dim fs As FileStream = New FileStream(strFName, FileMode。
Create, FileAccess。Write) Dim strLine As String = "" Dim sw As StreamWriter = New StreamWriter(fs, System。
Text。Encoding。Unicode) Dim Irowcount As Integer Dim Icolcount As Integer Dim i As Integer, Irow As Integer, Icol As Integer Irowcount = objDataSet。
Tables(tableName)。Rows。Count Icolcount = objDataSet。Tables(tableName)。Columns。Count Try For i = 0 To Icolcount - 1 strLine = strLine & objDataSet。
Tables(tableName)。Columns(i)。ColumnName()。ToString & vbTab Next sw。WriteLine(strLine) Convert。
ToChar(9) strLine = "" For Irow = 0 To Irowcount - 1 For Icol = 0 To Icolcount - 1 strLine = strLine & objDataSet。
Tables(tableName)。Rows(Irow)(Icol)。ToString() & vbTab Next sw。WriteLine(strLine) Convert。
ToChar(9) strLine = "" Next Finally sw。Close() fs。
Close() End Try End Sub ''' ''' '数据更新,增加,删除 ''' Public Sub updateTable(ByVal StrSql As String, ByVal objConSql As SqlConnection) Try If StrSql = "" Then Return End If objCommand = New SqlCommand(StrSql, objConSql) objCommand。
CommandType = CommandType。Text If objConSql。State = ConnectionState。Closed Then objConSql。
Open() End If Trans = objConSql。BeginTransaction objCommand。
Transaction = Trans objCommand。ExecuteNonQuery() Trans。Commit() Catch ese As Exception Try errNo = 1 MsgBox("数据更新时出现错误,请检查网络是否正常。
错误详细信息:" & ese。Message, MsgBoxStyle。Critical) Trans。Rollback() '如果更新异常则取消所有更新 Catch ex As Exception End Try Finally objConSql。
Close() '关闭连接 End Try End Sub ''' ''' 获取数据库的数据集 ''' Public Function getConn(ByVal SqlStr As String, ByVal TableName As String, ByVal objConSql As SqlConnection) Dim Index As Integer = 0 Try Try objDataSet = New DataSet 'objDataSet。
Tables(TableName)。Rows。Clear() Catch ex As Exception End Try If SqlStr <> "" Then objCommand = New SqlCommand() objCommand。
CommandText = SqlStr objCommand。CommandType = CommandType。Text objCommand。
Connection = objConSql objDataAdapter。SelectCommand = objCommand objDataAdapter。
Fill(objDataSet, TableName) Index = objDataSet。Tables(TableName)。Rows。Count End If Catch ex As Exception errNo = 1 MsgBox("提取数据出现错误,请检查网络是否正常。
错误详细信息:" & ex。Message, MsgBoxStyle。
Critical) End Try Return Index End Function 如果你还不知道,那就不好意思了,你只能重新学习一下VB在数据库方面的开发了。收起