ASP和SQL让我疯狂 [英] ASP and SQL driving me nuts

查看:42
本文介绍了ASP和SQL让我疯狂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经让我的页面进入最后的编辑页面。代码在加载时执行。变量通过会话传递但我得到SQL语法错误。我已经测试了sp我正在呼叫并且它正常工作。这里是代码


受保护的子页面_Load(ByVal发送者作为对象,ByVal e As System.EventArgs)处理Me.Load

Dim strSelDate

Dim strShift

Dim strAbsent

Dim strTO

Dim strHeadCount

Dim strSTDHeadCount

Dim strMPNotes

Dim Notes2

Dim strSQL

Dim strRID


strRID = Session.Item(" RID")。ToString()

strSelDate = Session.Item(" SelDate")。ToString()

strShift = Session .Item(" Shift")。ToString()

strAbsent = Session.Item(" Absent")。ToString()

strTO = Session.Item(" ; TO")。ToString()

strHeadCount = Session.Item(" HeadCount")。ToString()

strSTDHeadCount = Session.Item(" STDHeadCount")的ToString ()

strMPNotes = Session.Item(" Notes")。ToString()

''Notes2 = strMPNotes.Replace("''"," '''''")

strSQL =" UP_MANPOWER_RECORD_UPDATE''" &安培; strSelDate& '',''" &安培; strShift& '', &安培; strHeadCount& , &安培; strSTDHeadCount& , &安培; strAbsent& , &安培; strto& ",''" &安培; Notes2& '', &安培; strRID

Dim objConn As New Data.SqlClient.SqlConnection(" Data Source = XXXXXX; Initial Catalog = XXXXXX; User ID = XXXXXX; password = XXXXXX;")

Dim objCmd As New Data.SqlClient.SqlCommand(strSQL,objConn)

objConn.Open()

objCmd.ExecuteNonQuery()

objConn 。关闭()


结束子


这是'我得到的错误:


System.Data.SqlClient.SqlException:第1行:''''附近的语法不正确。


任何人都可以启发这个溺水的菜鸟吗?

I have gotten my pages to work up to the final edit page. The code executes on load. Variables are passed by session but I get an SQL syntax error. I''ve tested the sp I''m calling and it works correctly. Here''s the code"

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strSelDate
Dim strShift
Dim strAbsent
Dim strTO
Dim strHeadCount
Dim strSTDHeadCount
Dim strMPNotes
Dim Notes2
Dim strSQL
Dim strRID

strRID = Session.Item("RID").ToString()
strSelDate = Session.Item("SelDate").ToString()
strShift = Session.Item("Shift").ToString()
strAbsent = Session.Item("Absent").ToString()
strTO = Session.Item("TO").ToString()
strHeadCount = Session.Item("HeadCount").ToString()
strSTDHeadCount = Session.Item("STDHeadCount").ToString()
strMPNotes = Session.Item("Notes").ToString()
''Notes2 = strMPNotes.Replace("''", "''''")
strSQL = "UP_MANPOWER_RECORD_UPDATE ''" & strSelDate & "'', ''" & strShift & "'', " & strHeadCount & ", " & strSTDHeadCount & ", " & strAbsent & ", " & strTO & ", ''" & Notes2 & "'', " & strRID
Dim objConn As New Data.SqlClient.SqlConnection("Data Source=XXXXXX;Initial Catalog=XXXXXX;User ID=XXXXXX;password=XXXXXX;")
Dim objCmd As New Data.SqlClient.SqlCommand(strSQL, objConn)
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()

End Sub

Here''s the error I get:

System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near ''.''.

Can anyone enlighten this drowning noob??

推荐答案

您是否正确处理文本中的单引号?

您需要对您尝试插入的所有文本执行引号替换。

所以''需要成为其中两个'''''(注意:不是但是''''没有空格)
Are you properly dealing with single quotes in your text?
You need to do a quote replace on all text you try to insert.
so a '' needs to become two of them '''' (Note: not a " but '' '' without the space)



你是否妥善处理单身你的文字中的引用?

你需要在你试图插入的所有文本上做一个引号替换。

所以''需要成为其中两个'''' '(注意:不是但''''没有空格)
Are you properly dealing with single quotes in your text?
You need to do a quote replace on all text you try to insert.
so a '' needs to become two of them '''' (Note: not a " but '' '' without the space)



这一行用备注字符串中的双引号替换单引号。


Notes2 = strMPNotes.Replace("''","''''")

This line replaces single quotes with double quotes in the notes string.

Notes2 = strMPNotes.Replace("''", "''''")


嗯,它在你原来的帖子中注释了一件事。


您是否正在为所有其他字符串执行此操作?
Well, it''s commented out in your original post for one thing.

And are you doing it for all your other strings too?


这篇关于ASP和SQL让我疯狂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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