在我的数据库中进行简单查询时遇到问题。 我将查询结果放在String列表中,然后在dataGridView中显示列表。 我的DB是这样的
Time | Operations
......|...............
......|...............
......|...............
在操作列中,我有很长的字符串(大约24000个字符)。 我的代码是
Public time= New List(Of String)
Public operations= New List(Of String)
query = "SELECT time, operations FROM TABLE1"
Try
SQLCon.Open()
SQLCmd = New SqlCommand(query, SQLCon)
SQLDA = New SqlDataAdapter(SQLCmd)
SQLDataset = New DataSet()
SQLDA.Fill(SQLDataset)
'READ DIRECTLY FROM DATABASE
Dim R As SqlDataReader = SQLCmd.ExecuteReader
While R.Read
time.add(R(0).ToString)
operations.add(R(1).ToString)
End While
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
If SQLCon.State = ConnectionState.Open Then
SQLCon.Close()
End If
End Try
End Sub
要在dataGridView中显示我已经使用过:
For i = 0 To operations.count - 1
dataGridView1.Rows.Add(time(i), operations(i))
Next
当我在dataGridView中显示时,操作列中的某些项目为空白。 实施例
Time | Operations
11 feb|operations1=2................
11 feb|operations1=7................
12 jan|operations1=5................
13 jan|
14 jan|operations1=5................
20 jan|operations1=5................
如果我尝试在Msgbox中显示相关项目,操作(索引),我可以看到值,但在datagridview中我不能。 你能帮我吗?谢谢