'ขึ้น Error : Could not update; currently locked by user 'Admin' on machine 'KONETWORK-NJ'.
Public Function QueryExecuteNonQuery(ByVal strSQL As String) As Boolean
objConn = New OleDbConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
Try
objCmd = New OleDbCommand()
With objCmd
.Connection = objConn
.CommandType = CommandType.Text
.CommandText = strSQL
End With
objCmd.ExecuteNonQuery()
Return True '*** Return True ***'
Catch ex As Exception
Return False '*** Return False ***'
End Try
End Function
Code (VB.NET)
Dim STRSALES As String = ""
Dim ISINSSALES As Boolean = False
Dim iSALES As Integer
For iSALES = 0 To TBSALES.Rows.Count - 1
STRSALES = " INSERT INTO SALES (SalesDate,RouteNo,InvNo,BILLITEM,CustCode,StockGroup,SHCode,QTY,Discount,Amount,PriceBig,PriceSmall,PVAT,LastUpdate) "
STRSALES &= " VALUES ('@SalesDate',@RouteNo,@InvNo,'@BILLITEM','@CustCode','@StockGroup',@SHCode,@QTY,@Discount,@Amount,@PriceBig,@PriceSmall,@PVAT,'@LastUpdate')"
STRSALES = STRSALES.Replace("@SalesDate", TBSALES.Rows(iSALES).Item("SALEDATE").ToString)
STRSALES = STRSALES.Replace("@RouteNo", CLng(TBSALES.Rows(iSALES).Item("ROUTENO")))
STRSALES = STRSALES.Replace("@InvNo", CLng(TBSALES.Rows(iSALES).Item("INVNO")))
STRSALES = STRSALES.Replace("@BILLITEM", TBSALES.Rows(iSALES).Item("BILLITEM").ToString)
STRSALES = STRSALES.Replace("@CustCode", TBSALES.Rows(iSALES).Item("CUSTCODE").ToString)
STRSALES = STRSALES.Replace("@StockGroup", TBSALES.Rows(iSALES).Item("STOCKGROUP").ToString)
STRSALES = STRSALES.Replace("@SHCode", CLng(TBSALES.Rows(iSALES).Item("SHCODE")))
STRSALES = STRSALES.Replace("@QTY", CLng(TBSALES.Rows(iSALES).Item("QTY")))
STRSALES = STRSALES.Replace("@Discount", CLng(TBSALES.Rows(iSALES).Item("DISCOUNT")))
STRSALES = STRSALES.Replace("@Amount", CLng(TBSALES.Rows(iSALES).Item("AMOUNT")))
STRSALES = STRSALES.Replace("@PriceBig", CLng(TBSALES.Rows(iSALES).Item("PRICEBIG")))
STRSALES = STRSALES.Replace("@PriceSmall", CLng(TBSALES.Rows(iSALES).Item("PRICESMALL")))
STRSALES = STRSALES.Replace("@PVAT", CLng(TBSALES.Rows(iSALES).Item("PVAT")))
STRSALES = STRSALES.Replace("@LastUpdate", TBSALES.Rows(iSALES).Item("LASTUPDATE").ToString)
ISINSSALES = clsSALES.QueryExecuteNonQuery(STRSALES)
If ISINSSALES = True Then
Response.Write("<br> LOAD SALES//" + CStr(iSALES))
End If
Next
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Public Class AccessDatabaseManager
Private connection As OleDbConnection
Private command As OleDbCommand
Private _connectionString As String
Private _commandString As String
Private commandMessage As String = "You must execute command."
Private commandSuccess As Boolean = False
Public Sub New()
'add default connection string here.
'_connectionString = "ใส่ connection string ของคุณ สำหรับเป็นค่า default"
'connection = New OleDbConnection(_connectionString)
End Sub
Public Sub New(ByVal connectionString As String)
_connectionString = connectionString
connection = New OleDbConnection(_connectionString)
End Sub
Public Property ConnectionString() As String
Get
Return _connectionString
End Get
Set(ByVal value As String)
_connectionString = value
connection = New OleDbConnection(_connectionString)
End Set
End Property
Public Property CommandString() As String
Get
Return _commandString
End Get
Set(ByVal value As String)
_commandString = value
command = New OleDbCommand(_commandString, connection)
End Set
End Property
Public ReadOnly Property IsSuccess() As Boolean
Get
Return commandSuccess
End Get
End Property
Public ReadOnly Property Message() As String
Get
Return commandMessage
End Get
End Property
Public Overridable Sub AddParameter(ByVal ParameterName As String, ByVal ParameterValue As Object)
command.Parameters.AddWithValue(ParameterName, ParameterValue)
End Sub
Public Overridable Function ExecuteQuery() As DataTable
Dim dataTable As New DataTable()
Try
Dim dataAdapter As New OleDbDataAdapter(Command)
dataAdapter.Fill(dataTable)
dataAdapter.Dispose()
commandMessage = "Command is successfully."
commandSuccess = True
Catch ex As Exception
commandMessage = ex.Message
commandSuccess = False
End Try
Return dataTable
End Function
Public Overridable Function ExecuteScalar() As Object
Dim Result As Object = 0
Try
sqlConnection.Open()
Result = sqlCommand.ExecuteScalar()
sqlConnection.Close()
commandMessage = "Command is successfully."
commandSuccess = True
Catch ex As Exception
commandMessage = ex.Message
commandSuccess = False
End Try
Return Result
End Function
Public Overridable Function ExecuteNonQuery() As Boolean
Try
sqlConnection.Open()
sqlCommand.ExecuteNonQuery()
sqlConnection.Close()
commandMessage = "Command is successfully."
commandSuccess = True
Catch ex As Exception
commandMessage = ex.Message
commandSuccess = False
End Try
Return commandSuccess
End Function
End Class
Date :
2010-03-31 15:29:11
By :
tungman
No. 3
Guest
Code (VB.NET)
Dim ISINSSALES As Boolean = False
Dim iSALES As Integer
For iSALES = 0 To TBSALES.Rows.Count - 1
Dim SALES As New AccessDatabaseManager()
SALES.CommandString = "INSERT INTO [SALES] ([SalesDate], [RouteNo], [InvNo], [BILLITEM], [CustCode], [StockGroup], [SHCode], [QTY], [Discount], [Amount], [PriceBig], [PriceSmall], [PVAT], [LastUpdate]) VALUES (@SalesDate, @RouteNo, @InvNo, @BILLITEM, @CustCode, @StockGroup ,@SHCode, @QTY, @Discount, @Amount, @PriceBig, @PriceSmall, @PVAT, @LastUpdate)"
SALES.AddParameter("@SalesDate", TBSALES.Rows(iSALES).Item("SALEDATE").ToString)
SALES.AddParameter("@RouteNo", CLng(TBSALES.Rows(iSALES).Item("ROUTENO")))
SALES.AddParameter("@InvNo", CLng(TBSALES.Rows(iSALES).Item("INVNO")))
SALES.AddParameter("@BILLITEM", TBSALES.Rows(iSALES).Item("BILLITEM").ToString)
SALES.AddParameter("@CustCode", TBSALES.Rows(iSALES).Item("CUSTCODE").ToString)
SALES.AddParameter("@StockGroup", TBSALES.Rows(iSALES).Item("STOCKGROUP").ToString)
SALES.AddParameter("@SHCode", CLng(TBSALES.Rows(iSALES).Item("SHCODE")))
SALES.AddParameter("@QTY", CLng(TBSALES.Rows(iSALES).Item("QTY")))
SALES.AddParameter("@Discount", CLng(TBSALES.Rows(iSALES).Item("DISCOUNT")))
SALES.AddParameter("@Amount", CLng(TBSALES.Rows(iSALES).Item("AMOUNT")))
SALES.AddParameter("@PriceBig", CLng(TBSALES.Rows(iSALES).Item("PRICEBIG")))
SALES.AddParameter("@PriceSmall", CLng(TBSALES.Rows(iSALES).Item("PRICESMALL")))
SALES.AddParameter("@PVAT", CLng(TBSALES.Rows(iSALES).Item("PVAT")))
SALES.AddParameter("@LastUpdate", TBSALES.Rows(iSALES).Item("LASTUPDATE").ToString)
ISINSSALES = SALES.ExecuteNonQuery()
If ISINSSALES = True Then
Response.Write("<br> LOAD SALES//" + CStr(iSALES))
End If
Next