CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    265

    DataGridView populate

    Hi,

    I'm working on VB.NET Express and SQL Server Express. I have a DataGridView control in the form, with 8 columns, of which one column, which has default values, is hidden and one column is already filled with default values. I want to populate the DataGridView with records that exists in the database by selecting the record, based on the conditions in the SQL statement. And the record should be displayed in order of the hidden column values, without disturbing the default value column that is not hidden. How can I accomplish this? I have done some code, but it is not working. Here it is:

    Code:
       Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            'bolOpen = True
    
            Dim strProj As String
            strProj = LV.SelectedItems(0).Text
            Dim strItem(2) As String
            strItem = strProj.Split("-")
    
            With EntryFrm
                .txtRFS.Text = strItem(0)
                .txtPName.Text = strItem(1)
            End With
    
            Dim strCon As String = My.Settings.ConnectString
            Dim sqlConn As New SqlConnection(strCon)
            Dim Cmd As SqlCommand
    
            Dim DeptID As Integer
    
            DeptID = cboDept.SelectedIndex.ToString + 1
    
            Cmd = New SqlCommand("SELECT SDATE, EDATE, TLHRS, PHRS, THRS, COMP FROM PDETAILS WHERE RFS = " & strItem(0) & _
            " AND DEPTID = " & DeptID & " ORDER BY PHASEID", sqlConn)
    
            Dim DA As SqlDataAdapter
            Dim DS As New DataSet
    
            DA = New SqlDataAdapter(Cmd)
            DS = New DataSet
    
            DA.Fill(DS, "PDetails")
    
            EntryFrm.DGV.DataSource = DS
            EntryFrm.DGV.DataMember = "PDetails"
    
            Me.Close()
    
        End Sub

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: DataGridView populate

    at first glance what can i say is that dont close the form - remove this line "Me.Close()"
    Busy

  3. #3
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: DataGridView populate

    erase erase .. i thought it was in the main form hehe.. anyway, does the column header appear in the datagridview? if any field in WHERE clause of your SELECT statement is string you must enclose it in quotes.
    Busy

  4. #4
    Join Date
    Apr 2004
    Posts
    265

    Re: DataGridView populate

    I got it to work after adding DataPropertyName to every column! But then, the column in which the default values were displayed, got erased and shows blank. Why?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured