473,698 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET Execute Multiple SQL Statements using OleDb command

22 New Member
I would like to execute multiple SQL Statement using OleDB command but its coming up with error " Characters found after end of statement"

Below is my pieces of code.

Expand|Select|Wrap|Line Numbers
  1. Public Class DalOleDb
  2. Public Class DalOleDb
  3. Private _dss As DataSet
  4.     Private _daa As OleDbDataAdapter
  5.     Private _cnn As OleDbConnection
  6.     Private _cmd As OleDbCommand
  7.     Private _drr As OleDbDataReader
  8.     Private _cnnStr As String
  9.  
  10.     Public Sub New()
  11.         Try
  12.             cnn = New OleDbConnection(cnnString)
  13.             daa = New OleDbDataAdapter()
  14.             dss = New DataSet()
  15.             cmd = New OleDbCommand()
  16.         Catch ex As Exception
  17.             Throw New Exception(ex.Message)
  18.         End Try
  19.     End Sub
  20.  
  21. Sub DeleteBatch()
  22. Try
  23.  
  24. 'Delete batches related to this company
  25.             sb = sb.Append("DELETE FROM BATCH_HEADERS WHERE BH_CUSTNUMB=" & "'" & CompanyCode & "'")
  26.             sb = sb.Append(";")
  27.             sb = sb.Append("DELETE FROM BATCH_DETAILS WHERE BD_CUSTNUMB=" & "'" & CompanyCode & "'")
  28.             sb = sb.Append(";")
  29.             sb = sb.Append("DELETE FROM BATCH_HEADERS_BACKUP WHERE BHB_CUSTNUMB=" & "'" & CompanyCode & "'")
  30.             sb = sb.AppendLine
  31.             sb = sb.Append("DELETE FROM BATCH_DETAILS_BACKUP WHERE BDB_CUSTNUMB=" & "'" & CompanyCode & "'")
  32.             sb = sb.Append(";")
  33. ExecuteSQL(sb.ToString())
  34.  
  35.   Catch ex As Exception
  36.             Throw New Exception(ex.Message)
  37.         Finally
  38.         End Try
  39.   End Sub
  40.  
  41.  
  42. Sub ExecuteSQL(ByRef SQLStatement As String)
  43.         Try
  44.             cmd.CommandText = SQLStatement
  45.             cmd.Connection = cnn
  46.             cnn.Open()
  47.             cmd.ExecuteNonQuery()
  48.         Catch ex As Exception
  49.             Throw New Exception(ex.Message)
  50.         Finally
  51.             cnn.Close()
  52.         End Try
  53.     End Sub
  54.  
End Class
Sep 4 '09 #1
2 12915
kunal pawar
297 Contributor
look every thing right

plz change code

sb = sb & "DELETE FROM BATCH_HEADERS WHERE BH_CUSTNUMB=" & "'" & CompanyCode & "';"

sb = sb & "DELETE FROM BATCH_DETAILS WHERE BD_CUSTNUMB=" & "'" & CompanyCode & "';"
sb = sb & "DELETE FROM BATCH_HEADERS_B ACKUP WHERE BHB_CUSTNUMB=" & "'" & CompanyCode & "';"
sb = sb & "DELETE FROM BATCH_DETAILS_B ACKUP WHERE BDB_CUSTNUMB=" & "'" & CompanyCode & "';"
Sep 4 '09 #2
Frinavale
9,735 Recognized Expert Moderator Expert
I recommend using Parameters instead of dynamically building your query string.
See http://bytes.com/topic/net/insights/...e-your-program for an example.
Sep 4 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
16754
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from customers; I can execute each statement individually but get the 'you have an error in
8
3567
by: DB2 Novice | last post by:
I am trying to use DB2 Control Centre (version 8.2) to load one flat file into multiple tables. However, I don't see the options in Control Centre that allows that. Anyone knows how to do this? DB2 Novice
2
6751
by: Nabil | last post by:
I am new to DB2 and here is my situation. I have 2 temp tables where I am trying to insert data (from 2 select statements) DECLARE v_t1 VARCHAR(50); DECLARE v_t1 VARCHAR(50); DECLARE stmt1 STATEMENT; DECLARE stmt2 STATEMENT;
4
7804
by: NS | last post by:
Hi, I am trying to execute a prepare statement using oledb provider for DB2. The command.Prepare() statement is giving me an exception " No error information available: DB_E_NOCOMMAND(0x80040E0C)." My code is very simple and is working with other oledb provider, like SQL Server and oracle.
1
2406
by: svijay | last post by:
hi I have got a strange problem. May I know any solution for this. Here is the detailed description about the problem We have got a mainframe system and also production and development server.
1
4836
by: TheSteph | last post by:
Hi, I need some Advice.. What is the best practice to execute multiple "nonQuery" SQL operations in a transaction ? 1) Execute all in one "sqlCommand.ExecuteNonQuery();" : sqlCommand.CommandText =
1
2495
by: arthy | last post by:
Hi, Is it possible to execute multiple statements on to the database using a single dbconnection object.what is the drawback in using .If not possible ,then how can the execution of multiple statements using a single object be done. thanks in advance, arthy
1
1370
by: Muhamamd Khayyam | last post by:
I am passing a query to Oracle 9i using Oledb.command object. Code is Dim c As OleDb.OleDbCommand Dim sOURCE As BindingSource Dim DR As OleDb.OleDbDataReader Connect.Connect("scott", "tiger", "ORCL", "ORACLE") ' A module for connection string c = New OleDb.OleDbCommand("select * from EMP WHERE HIREDATE = '07-AUG-07', Connect.V_DbConnection) '' Connect.V_DbConnection is a connection object ...
0
2051
by: teckguan | last post by:
Hi everyone, I would like to ask how am I going to execute multiple scripts using UNIX command? I have found a command to execute. However, I cannot execute it. The command is db2 -txf <<EOF $SQLSTMTset schema ADMIN; I do think that maybe the author types wrongly. I hope you guys can help. Thanks.
0
8672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4361
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.