[英]How to remove white space in VB.Net
In the following code SqlDataReader 'dr' does not read the "SubjectCode" of subjects whose names contain white space; 在下面的代码中,SqlDataReader'dr'不会读取名称包含空格的主题的“ SubjectCode”; example English Language, Social Studies, Principles of Cost Accounting, etc. from the subjects table.
例如,主题表中的英语,社会研究,成本会计原理等。
I'd therefore be more than grateful if someone could very kindly help me out immediately. 因此,如果有人可以立即很好地帮助我,我将不胜感激。
cmd = New SqlCommand( _
"select subjectCode from ProgramDetails.subjects where subjectname='" & _
Trim(subname) & " ' ", cn)
dr = cmd.ExecuteReader
If dr.Read Then
subcode = dr(0)
End If
dr.Close()
SQL-Parameters
SQL-Parameters
进行SQL注入 LIKE
with the wildcard %
instead: LIKE
与通配符%
使用: For example: 例如:
Dim sql = "Select subjectCode From ProgramDetails.subjects where subjectname Like @subname"
Using con = New SqlConnection(connectionString)
Using cmd = New SqlCommand(sql, con)
cmd.Parameters.AddWithValue("@subname", String.Format("%{0}%", "english"))
Con.Open()
Using rd = cmd.ExecuteReader()
While rd.Read()
Dim subjectCode = rd.GetString(0)
' ... '
End While
End Using
End Using
End Using
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.