I have set some dataSet and BindingSource and used this code.
These code should show 5 rows of record but it shows 6 empty rows only (including 1 empty new lines),
the values form database can't be matched:
Source
Import Oracle.DataAccess.Client
Public Class Form1
Dim dbCommand As OrcaleCommand
Dim sAdapter As OracleDataAdapter
Dim sBuilder As OracleCommandBuilder
Dim dsData As DataSet
Dim dtData As DataTable
Private Sub loadBtn_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loadBtn.Click
Dim connStr As String = "DataSource=.;Initial Catalog=pubs;Integrated Security=Time"
Dim sql As String = "SELECT * FROM (SELECT * FROM LIBBKN_BATCH ORDER BY BATCH_NO) WHERE ROW_NAME <=5"
Dim conn As OrcaleConnection(connStr)
conn.Open()
dbCommand = New OrcaleCommand(sql, conn)
sAdapter = New OrcaleDataAdapter(dbCommand)
sBuilder = New OrcaleCommandBuilder(sAdapter)
dsData = New DataSet()
sAdapter.Fill(sDs,"BATCH")
sTable = sDs.Tables("BATCH")
conn.Close()
Me.dgv.DataSource = dsData.Tables("BATCH")
Me.dgv.DataSource.ReadOnly = True
End Sub
End Class
After some search from internet, I found my problem is I set the "name" of column only,
I should also set "DataPropertyName" value, value need to same as database column name.
(This Image from ShunNien's Blog)
Reference
https://stackoverflow.com/questions/24049866/winforms-datagridview-showing-blank-rows
https://shunnien.github.io/2015/12/15/DataGridView-in-winform-1/
No comments :
Post a Comment