VBNEt2008 Problem with using SQLCMD Parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JaneDurban
    New Member
    • Sep 2010
    • 1

    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:
    Code:
     Private Sub FSaveNewData()
          
       Dim strSqlInsert As String = Nothing
    
       Try
        sqlconn = New SqlConnection(connstr)
        sqlconn.Open()
    
        strSqlInsert &= "  Insert into TblSales ( SalesID,  CustomerName, SaleQty, SalePrice ) "          
        strSqlInsert &= " Values ( @SalesID, @CustName, @SalesQty, @SalesPrice ) " 
        strSqlInsert &= "  Where  (SalesID <> @SalesId ) "
    
       sqlcmd = New SqlCommand(strSqlInsert, sqlconn)
    
       With sqlcmd.Parameters
         .AddWithValue("@SalesId", SqlDbType.Int).Value = Convert.ToInt32(intSalesId)
        .AddWithValue("@CustName", SqlDbType.NVarChar).Value = CType(Me.txtCustomerName.Text, String)
        .AddWithValue("@SalesQty", SqlDbType.Int).Value = Convert.ToInt32(Ctype(me.txtSalesQty.text, integer)                
       .AddWithValue("@SalePrice", SqlDbType.Money).Value = Convert.ToDouble(CType(Me.txtSalesPrice.Text, Integer))              
    End With
    
       sqlcmd.ExecuteNonQuery()
       sqlconn.Close()
       sqlcmd.Dispose()
    
     Catch ex As Exception
        MessageBox.Show(ex.Message)
     End Try
    
        End Sub

    Regards,
    Jane Durban
    NewYork
Working...