473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

VBNEt2008 Problem with using SQLCMD Parameters

Dear Friends,
The SQLCMD parameter setting I encounter problem with this part of the coding:
strSqlInsert &= " Where (SalesID <> @SalesId ) "

Here is the error message:
Incorrect syntax near the Keyword 'Where'

Using SQL String with SQLCMD parameters to create a new record at SQLSERVER2000 table, TBLSales. but t's not working with WHERE statement.

Here are the coding:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub FSaveNewData()
  2.  
  3.    Dim strSqlInsert As String = Nothing
  4.  
  5.    Try
  6.     sqlconn = New SqlConnection(connstr)
  7.     sqlconn.Open()
  8.  
  9.     strSqlInsert &= "  Insert into TblSales ( SalesID,  CustomerName, SaleQty, SalePrice ) "          
  10.     strSqlInsert &= " Values ( @SalesID, @CustName, @SalesQty, @SalesPrice ) " 
  11.     strSqlInsert &= "  Where  (SalesID <> @SalesId ) "
  12.  
  13.    sqlcmd = New SqlCommand(strSqlInsert, sqlconn)
  14.  
  15.    With sqlcmd.Parameters
  16.      .AddWithValue("@SalesId", SqlDbType.Int).Value = Convert.ToInt32(intSalesId)
  17.     .AddWithValue("@CustName", SqlDbType.NVarChar).Value = CType(Me.txtCustomerName.Text, String)
  18.     .AddWithValue("@SalesQty", SqlDbType.Int).Value = Convert.ToInt32(Ctype(me.txtSalesQty.text, integer)                
  19.    .AddWithValue("@SalePrice", SqlDbType.Money).Value = Convert.ToDouble(CType(Me.txtSalesPrice.Text, Integer))              
  20. End With
  21.  
  22.    sqlcmd.ExecuteNonQuery()
  23.    sqlconn.Close()
  24.    sqlcmd.Dispose()
  25.  
  26.  Catch ex As Exception
  27.     MessageBox.Show(ex.Message)
  28.  End Try
  29.  
  30.     End Sub
  31.  

Regards,
Jane Durban
NewYork
Sep 15 '10 #1
0 912

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

Similar topics

2
by: jarrel | last post by:
do anyone know how to create xml file with using C and converting to Pocket PC?please provide me some source code.your help is highly appreciated.thanks
2
by: TaeHo Yoo | last post by:
Have a problem with using cursors in SQL server enterprise manager. My code sql query is followed --------------------------------------- DECLARE @element_name varchar(100) DECLARE...
0
by: Bernie | last post by:
Hi All, I have a weird problem with using flash on aspx pages. It goes like this: I have some links with query string parameters in the page. The same links appear as regular "a href" and also...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
7
by: Kenneth Brody | last post by:
The recent thread on "query about main()" got me thinking... As I recall, calling a function with the wrong parameters causes undefined behavior. (These all assume that no prototype of foo()...
3
by: Velislav | last post by:
Hi, I've got a setup project which installs SQL Server Express as a prerequisite to my program. The problem is that by default it's installed using the SQLEXPRESS instance name and Windows...
14
by: flamingskullz | last post by:
Hi Guys, im trying to get VB to run the regedit.exe function with the following command line regedit.exe /E C:\VB.txt "HKEY_LOCAL_MACHINE\Software\Aberlink 3D" Anybody have any ideas? The...
1
by: jelumalai | last post by:
I am using display:none with using Table. When show the onClick using javascript. Then it will show, again i will hide, content only hidden, but that table doesn't hide. <script> function...
2
by: Alexnb | last post by:
Okay, I am not sure if there is a better way of doing this than findAll() but that is how I am doing it right now. I am making an app that screen scapes dictionary.com for definitions. However, I...
2
by: lyle777 | last post by:
I need help with using continue in my loop. they say that when using continue in the loop that is nested, depending on the condition of the continue statement, execution should jump to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.