Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

show a Datagridview in the form

$
0
0

Hi all

I'm trying to get data from sql server then to fil it in a datagridview, but no result is displayed after excuting the code.

here is my code:

dim strSourceTbl AsString 

dimstrSourceColumns AsString

dimstrWhereCondition AsString

dim daSelect As SqlClient.SqlDataAdapter

dim dtSourceValues As DataTable

dim dgSourceValues As System.Windows.Forms.DataGridView

dim bindSource As BindingSource

 dim cmdSelectValues AsNew SqlClient.SqlCommand

dim cmdComandBuilderAs SqlClient.SqlCommandBuilder

dimdsSelectAsNew DataSet

Dim strSelectValuesAsString

Dim strWhereAsString

Try

            strSourceColumns = txtSourceColumns.Text

            strSelectValues ="SELECT "& strSourceColumns& " FROM "&frmSource.strSourceDB & ".dbo."& strSourceTbl

            txtValues.Text = strSelectValues

If txtWhere.Text <>""Then


                strWhere = txtWhere.Text.ToString

                strSelectValues = strSelectValues &" WHERE "& strWhere

EndIf

            txtValues.Text = strSelectValues

Me.daSelect =New SqlClient.SqlDataAdapter(strSelectValues, frmSource.cnSqlConnectToSource)

Me.daSelect.Fill(Me.dsSelect)

            dgSourceValues =

New DataGridView

            dgSourceValues.DataSource = dsSelect.Tables.Item(0)


SqlDream


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>