简体   繁体   English

在vs2010 vb.net中获取sql语句的结果

[英]getting the result of a sql statement in vs2010 vb.net

I am doing a sql statement to get all the data that starts with "A" in the database. 我正在执行一条sql语句,以获取数据库中所有以“ A”开头的数据。

Sub searchMap()
    Dim connectionString As String = ConfigurationManager.ConnectionStrings("WeddingPerfectionConnectionString").ConnectionString
    Dim connection As SqlConnection = New SqlConnection(connectionString)
    connection.Open()
    Dim sql As String = "SELECT LocationName FROM MapSearch WHERE LocationName=" Like ("1%")
    Dim command As SqlCommand = New SqlCommand(sql, connection)
    Dim reader As SqlDataReader = command.ExecuteReader()
    Dim customerId As Integer
    If (reader.Read()) Then
        customerId = reader.GetValue(0)
    End If
    reader.Close()
End Sub

And i would like to get the result and display it in a lable. 我想得到结果并显示在标签中。

How can i go about doing it? 我该怎么做呢?

In SQL-Server: 在SQL Server中:

Dim sql As String = "SELECT LocationID, LocationName FROM MapSearch WHERE LocationName LIKE 'A%'"

LIKE (Transact-SQL) 像(Transact-SQL)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM