Bri*_*ian 0 .net vb.net sql-server ado.net
这是我正在使用的:
Dim connstr = "data source=mydatasource;initial catalog=gcs_dw;persist security info=True;user id=myuser;password=mypassword;Asynchronous Processing=True"
Dim sqlquery = "SELECT * FROM Customer WHERE CITY = 'Anytown'"
Dim connection As SqlConnection = New SqlConnection(connstr)
connection.Open()
Dim command As SqlCommand = connection.CreateCommand()
command.CommandText = sqlquery
Dim reader As SqlDataReader = command.ExecuteReader()
reader.Read()
Console.WriteLine(reader.ToString)
connection.Close()
Console.Read()
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我正在尝试将查询结果显示到命令行,目前显示的只是"System.Data.SqlClient.SqlDataReader".我的SQL查询的结果在哪里,为什么我无法检索它们?
这就是问题:
Console.WriteLine(reader.ToString)
Run Code Online (Sandbox Code Playgroud)
您ToString直接在阅读器上调用,而不是从当前行询问它是否具有特定值.就像是:
Console.WriteLine(reader.GetString(0))
Run Code Online (Sandbox Code Playgroud)
应该没事.
| 归档时间: |
|
| 查看次数: |
9924 次 |
| 最近记录: |