SELECT * FROM不返回所有行

时间:2011-12-16 00:32:59

标签: vb.net sql-server-2008 select

我无法在任何地方找到任何对此错误的引用。我在本地PC上运行SQL Express 2008并创建了许多表。除一个“联系人”外,所有功能似乎都正常。它包含姓名,电话号码等......目前有10行(不是真正的数据,只是东西)。当我在Management Studio中查看它时,有10行,但是当我执行以下操作时,我只返回前3行。我已经运行DBCC CHECKDB并且没有错误。我可以毫无问题地添加新行。

VB.Net代码:

conString = String.Format("server={0};uid={2};pwd={3};database={1};", server, database, dbID, dbPass)
myConn = New SqlConnection("")

'Open the connection.
myConn.ConnectionString = conString
myConn.Open()

Dim com As String
com = "SELECT * FROM contact"

myCmd = myConn.CreateCommand
myCmd.CommandText = com
myReader = myCmd.ExecuteReader()

Do While
   myReader.Read()
   Dim contact As nameClass = New nameClass
   contact.id = myReader.GetInt32(0)
   contact.name = myReader.GetString(1)
   contact.supplierID = myReader.GetInt32(2)
   contact.customerID = myReader.GetInt32(3)
   contact.phone = myReader.GetString(4)
   contact.fax = myReader.GetString(5)
   contact.mobile = myReader.GetString(6)
   contact.email = myReader.GetString(7)
   contact.notes = myReader.GetString(8)
Loop
myReader.Close()
myConn.Close()

SSMS的数据库内容是:

Index Name   Supp  Cust     phone     fax       mobile      eMail          created             user
+--+--------+-----+-----+---------+---------+----------+------------+------------------------+---
16 | fred a | -1  |  -1 | 09809809| 09809809| 090980980| lkjlkjlkjlk| 2011-12-15 11:12:25.000| 3
17 | fred b | -1  |  -1 | 098098  | 09809809| 09809809 | llkjlkjlkkl| 2011-12-15 11:13:02.000| 3
18 | fred c |  1  |  -1 | 0980980 | 09809809| 09809809 | lkjhkljlk  | 2011-12-15 11:13:34.000| 3
19 | fred d | -1  |   2 | 98098098| 09809809| 09809890 | kjhkjhkj   | 2011-12-15 11:13:54.000| 3
1  | John   | -1  | -1  | 89769887| 0980980 | 0980980  | kjhkjkj    | 2011-11-12 23:34:12.000| 3
2  | Bob    | -1  | -1  |         |         |          | ;lk;lkl;   | 2011-11-12 23:40:39.000| 3
3  | Mike   | -1  | -1  |         |         |          |            | 2011-11-12 23:44:18.000| 3
4  | Louise | -1  | -1  | 98798789|         |          |            | 2011-11-12 23:43:38.000| 3
5  | Colin  | -1  | -1  |         |         |          |            | 2011-12-12 10:34:15.000| 3
6  | harry  |  3  | -1  | 93872983|         |          | kasjhkajsh | 2011-12-14 02:16:07.000| 3

1 个答案:

答案 0 :(得分:1)

一些建议:

您确定您的应用程序是否连接到与您从SQL Management Studio连接的服务器和数据库相同的服务器和数据库?

您可以尝试运行sql跟踪并查看应用程序向数据库发送的查询。

我假设你在查询分析器中运行“SELECT * FROM contact”。什么架构所有者,dbo?

尝试在您的应用程序中将查询更改为SELECT * FROM dbo.contact“并从查询分析器运行相同的查询。

另外(如评论中所示),您需要遍历读者以实际读出数据。