如何在VB.NET中使用整数值的SQL查询WHERE子句?调试窗口服务? [英] How to put SQL query WHERE clause with integer value in VB.NET? Debugging window service?

查看:81
本文介绍了如何在VB.NET中使用整数值的SQL查询WHERE子句?调试窗口服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我很抱歉,如果这对你来说太容易了,但我对编程很陌生,所以我不知道我需要什么方法。



在SQL Server Management Studio中,我有一个获取活动用户信息的查询。



Okay I'm sorry if this was too easy for you but I'm kinda new to programming so I don't know what approach I need for this.

In SQL Server Management Studio I have a query that gets the active User information.

SELECT DISTINCT UserID FROM tblUserInfo WHERE IsActive = '1'





我的问题是我不知道怎么把带有整数值的where子句放在VB.Net中





My problem is that I don't know how to put where clause with integer value in VB.Net

Public Shared Function FnGetUserID() As List(Of String)
        Dim lstUserID As New List(Of String)

        Dim cmd As New SqlCommand()
        Try
            cmd.Connection = DBConn.getConn()
            cmd.CommandType = CommandType.Text
            cmd.Connection.Open()

            Dim sql As String = ""
            sql += " SELECT DISTINCT UserID FROM tblUserInfo"

            cmd.CommandText = sql

            Dim sqlRdr As SqlDataReader = cmd.ExecuteReader
            While sqlRdr.Read
                lstUserID.Add(sqlRdr.Item("UserID").ToString)
            End While

            cmd.Connection.Close()
            cmd.Dispose()
        Catch ex As Exception
            cmd.Dispose()
            'lstSite = Nothing
        End Try

        Return lstUserID
    End Function





希望你能帮助我。



An d我也正在做项目窗口服务,我也是新手,所以当我想测试我的项目时,我也只是点击VB studio中的启动调试按钮,窗口服务将运行和调试但是当我单击它会弹出一个窗口弹出Windows服务启动失败和无法从命令行或调试器启动服务。首先必须安装Windows服务(使用installutil.exe),然后使用ServerExplorer,Windows服务管理工具或NET START命令启动。



那是什么是吗?我是否正在调试我的Window服务?



我尝试了什么:



啊。我试过这段代码



Hope you can help me with this.

And also I'm doing a Project Window Service and I'm also new with this so I figure when I want to test my project I also just click the start debugging button in VB studio and the Window Service will run and debug but when I click it there's a window pop-up saying "Windows Service Start Failure" and "Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command."

What does that mean? And am I doing the right way of debugging my Window Service?

What I have tried:

Ah. I tried this code

sql += " SELECT DISTINCT UserID FROM tblUserInfo WHERE IsActive = '" & 1 & "' "



嗯,我真的很无能为力。


Well I'm really clueless on how I could do this.

推荐答案

你可以用这种方式编写你的代码

you can write your code in this way
dim sql as string= " SELECT DISTINCT UserID FROM tblUserInfo WHERE IsActive = 1" 

this beacause your value is an integer and sql doesn't want ' for integer.

for debug your windows service you can use this tutorial, although you should use a windows application for testing your code (you can change a little of your code in debug mode).

<a href="https://www.youtube.com/watch?v=pfF-GNK5ygE">How to Debug Windows Service Source Code in Microsoft Visual Studio - YouTube</a>[<a href="https://www.youtube.com/watch?v=pfF-GNK5ygE" target="_blank" title="New Window">^</a>]


I hope it was useful


这篇关于如何在VB.NET中使用整数值的SQL查询WHERE子句?调试窗口服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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