0
매개 변수에 값을 전달하려고 시도했지만 반환되는 값은 아무 것도 아닙니다. 매개 변수없이 간단한 SQL 명령을 사용하면 데이터베이스에서 모든 데이터를 검색 할 수 있습니다. 당신은 문자열 @criteria
찾고 있습니까어떻게 sqldataadapter에 매개 변수를 전달할 수 있습니까?
Public Shared Function RetrieveData() As DataTable
Connection.Open()
Try
sql = "SELECT DEP_ID AS CODE, DEP_NAME AS DEPARTMENT FROM DEPART_TBL WHERE " & FieldName & " LIKE N'%@criteria%'"
da = New SqlDataAdapter
da.SelectCommand = New SqlCommand(sql, Connection.SQLConnection)
da.SelectCommand.Parameters.Add("@criteria", SqlDbType.NChar)
da.SelectCommand.Parameters("@criteria").Value = "KCL"
'da.SelectCommand.Parameters.Add("@criteria", SqlDbType.NChar, 10, "DEP_ID")
'Message.ShowInfo(da.SelectCommand.CommandText.ToString)
'Exit Function
dt = New DataTable
da.Fill(dt)
Catch ex As Exception
Message.ShowError(ex.Message)
End Try
da.Dispose()
Connection.Close()
Return dt
End Function
qu estion하지만 명령에 값을 추가하는 것과 동시에 변수에 값을 할당 할 수 있으며 문자열 매개 변수를 전달할 때 길이를 지정하는 것도 좋습니다. 그래서 당신의 코드는 다음과 같을 수 있습니다 :'da.SelectCommand.Parameters.Add ("@ criteria", SqlDbType.NChar, 50) .Value = "KCL"' – GarethD