我怎么...在VB.NET的SQL查询中'='附近的语法不正确 [英] How do i...incorrect syntax near '=' in SQL query in VB.NET

查看:69
本文介绍了我怎么...在VB.NET的SQL查询中'='附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AM尝试更新,但在'='附近得到此错误

语法


我是什么尝试过:



 con =新SqlConnection(cs)
con.Open()
Dim cb As String =更新CourseFeePayment设置CFP_ID = @ d1,PaymentID = @ d2,AdmissionNo = @ d3,Session = @ d4,TotalFee = @ d6,DiscountPer = @ d7,DiscountAmt = @ d8,PreviousDue = @ d9,罚款= @ d10,GrandTotal = @ d11,TotalPaid = @ d12,ModeOfPayment = @ d13,PaymentModeDetails = @ d14,PaymentDue = @ d16其中CFP_ID ='& txtCFPId.T​​ext& '
cmd =新SqlCommand(cb)
cmd.Connection = con
cmd.Parameters.AddWithValue(@ d1,Val(txtCFPId.T​​ext))
cmd .Parameters.AddWithValue(@ d2,txtFeePaymentID.Text)
cmd.Parameters.AddWithValue(@ d3,txtAdmissionNo.Text)
cmd.Parameters.AddWithValue(@ d4,txtSession。文本)
cmd.Parameters.AddWithValue(@ d6,txtCourseFee.Text)
cmd.Parameters.AddWithValue(@ d7,txtDiscountPer.Text)
cmd.Parameters.AddWithValue( @ d8,txtDiscount.Text)
cmd.Parameters.AddWithValue(@ d9,txtPreviousDue.Text)
cmd.Parameters.AddWithValue(@ d10,txtFine.Text)
cmd.Parameters.AddWithValue(@ d11,txtGrandTotal.Text)
cmd.Parameters.AddWithValue(@ d12,txtTotalPaid.Text)
cmd.Parameters.AddWithValue(@ d13, cmbPaymentMode.Text)
cmd.Parameters.AddWithValue(@ d14,txtPaymentModeD etails.Text)
cmd.Parameters.AddWithValue(@ d16,txtBalance.Text)
cmd.ExecuteNonQuery()
con.Close()
con = New SqlConnection( cs)
con.Open()
Dim cq As String =从CourseFeePayment_Join中删除,其中C_PaymentID =& txtCFPId.T​​ext&
cmd =新的SqlCommand(cq)
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
con.Open()
Dim cb1 As String =插入CourseFeePayment_Join(C_PaymentID,Month,FeeName,Fee)VALUES(& txtCFPId.T​​ext&,@ d1,@ d2,@ d3)
cmd = New SqlCommand(cb1)
cmd.Connection = con
'准备重复执行命令
cmd.Prepare()
'要插入的数据
For Each row As DataGridViewRow在dgw.Rows
如果不是row.IsNewRow那么
cmd.Parameters.AddWithValue(@ d1,row.Cells(0).Value)
cmd.Parameters.AddWithValue(@ d2,row.Cells(1).Value)
cmd.Parameters.AddWithValue(@ d3,Val(row.Cells(2).Value))
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
En d如果

解决方案

首先为什么你只拿

 txtCFPId.T​​ext 

通过在SQl查询中连接。

它易受SQL注入攻击。



请使用参数获取此值另外。

那么你也不需要处理varchar列的引号。这看起来像是导致问题。


AM trying to update but get this error

syntax near '='



What I have tried:

con = New SqlConnection(cs)
           con.Open()
           Dim cb As String = "Update CourseFeePayment set CFP_ID=@d1, PaymentID=@d2, AdmissionNo=@d3, Session=@d4,TotalFee=@d6, DiscountPer=@d7, DiscountAmt=@d8, PreviousDue=@d9, Fine=@d10, GrandTotal=@d11, TotalPaid=@d12, ModeOfPayment=@d13, PaymentModeDetails=@d14, PaymentDue=@d16 where CFP_ID= '" & txtCFPId.Text & "'"
           cmd = New SqlCommand(cb)
           cmd.Connection = con
           cmd.Parameters.AddWithValue("@d1", Val(txtCFPId.Text))
           cmd.Parameters.AddWithValue("@d2", txtFeePaymentID.Text)
           cmd.Parameters.AddWithValue("@d3", txtAdmissionNo.Text)
           cmd.Parameters.AddWithValue("@d4", txtSession.Text)
           cmd.Parameters.AddWithValue("@d6", txtCourseFee.Text)
           cmd.Parameters.AddWithValue("@d7", txtDiscountPer.Text)
           cmd.Parameters.AddWithValue("@d8", txtDiscount.Text)
           cmd.Parameters.AddWithValue("@d9", txtPreviousDue.Text)
           cmd.Parameters.AddWithValue("@d10", txtFine.Text)
           cmd.Parameters.AddWithValue("@d11", txtGrandTotal.Text)
           cmd.Parameters.AddWithValue("@d12", txtTotalPaid.Text)
           cmd.Parameters.AddWithValue("@d13", cmbPaymentMode.Text)
           cmd.Parameters.AddWithValue("@d14", txtPaymentModeDetails.Text)
           cmd.Parameters.AddWithValue("@d16", txtBalance.Text)
           cmd.ExecuteNonQuery()
           con.Close()
           con = New SqlConnection(cs)
           con.Open()
           Dim cq As String = "delete from CourseFeePayment_Join where C_PaymentID= " & txtCFPId.Text & ""
           cmd = New SqlCommand(cq)
           cmd.Connection = con
           cmd.ExecuteNonQuery()
           con.Close()
           con.Open()
           Dim cb1 As String = "insert into CourseFeePayment_Join(C_PaymentID,Month, FeeName, Fee) VALUES (" & txtCFPId.Text & ",@d1,@d2,@d3)"
           cmd = New SqlCommand(cb1)
           cmd.Connection = con
           ' Prepare command for repeated execution
           cmd.Prepare()
           ' Data to be inserted
           For Each row As DataGridViewRow In dgw.Rows
               If Not row.IsNewRow Then
                   cmd.Parameters.AddWithValue("@d1", row.Cells(0).Value)
                   cmd.Parameters.AddWithValue("@d2", row.Cells(1).Value)
                   cmd.Parameters.AddWithValue("@d3", Val(row.Cells(2).Value))
                   cmd.ExecuteNonQuery()
                   cmd.Parameters.Clear()
               End If

解决方案

First of all why are you taking only

txtCFPId.Text

by concatenating in SQl query.
Its vulnerable to SQL injection.

Please use parameter for this value also.
then you no need to take care of quotes for varchar columns also. which looks like causing the issue.


这篇关于我怎么...在VB.NET的SQL查询中'='附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆