我正在使用此代码来读取学生详细信息,但它会在#附近引发错误的错误语法 [英] I am Using this code to read student details but it throws an error incorrect syntax near #

查看:100
本文介绍了我正在使用此代码来读取学生详细信息,但它会在#附近引发错误的错误语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

For i = 0 To DataGridView1.Rows.Count - 1
                       Dim date1 As Date
                       date1 = DataGridView1.Rows(i).Cells(0).Value

                       cmd.CommandText = "select Remark from StudentAccountS where AdmissionID=" & Me.StudentID & " and StClass='" & ddClass.Text & "' and Dated=format(#" & date1 & "#,'dd-MMM-yy')"
                       dr1 = cmd.ExecuteReader
                       If dr1.Read Then

                           If IsDBNull(dr1(0)) Then

                           Else
                               DataGridView1.Rows(i).Cells(5).Value = dr1(0)

                           End If
                       End If
                       dr1.Close()

推荐答案

格式 part在SQL里面 - 它应该在外面...



但更重要的是,你应该永远不要创建以这种方式执行的SQL - 使用改为参数化查询: -



The format part is inside the SQL - it should be outside...

But more importantly than that, you should never create SQL to be executed in that manner - use a parameterised query instead:-

cmd.CommandText = "select Remark from StudentAccountS where AdmissionID=@StudentID  and StClass=@ddClass and Dated=@date1"

cmd.Parameters.AddWithValue("@StudentId", Me.StudentID) 





等......



etc...


这篇关于我正在使用此代码来读取学生详细信息,但它会在#附近引发错误的错误语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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