Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I have 3 comboboxcolumn in datagridview.I want to display its value in grid if its value in database table is not null.Eg one column is caste.if this is null in my databse table then combobox column should be added to grid else caste value shold be seen in combobox when datagridview loads..Can any1 help me.
Below is my code:
Dim cast As Integer = 0
            Dim con As OdbcConnection = New OdbcConnection
            sql = "Select d.caste from datafile d where d.AC_NO = " & cmbVidhanNo.Text & " " + searchstring
            If rs.State = 1 Then rs.Close()
            rs.Open(sql, MainCon, 1, 3)
            Do While Not rs.EOF
                If Not IsDBNull(rs.Fields(0).Value) Then
                    cast = rs.Fields(0).Value
                End If
                If Not IsDBNull(cast) Then
                    With col_Caste
                        .Name = "Caste"
                        .HeaderText = "Caste"
                        .DataPropertyName = cast
                        .ReadOnly = False
                    End With
    
                Else
                    sql = "Select Desc from Category where Catgry = 1"
                    con.ConnectionString = connstring
                    If con.State = ConnectionState.Open Then con.Close()
                    con.Open()
                    Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, con)
                    da.Fill(ds, "Caste")
    
                    With col_Caste
                        .Name = "Caste"
                        .HeaderText = "Caste"
                        .DataSource = ds.Tables("Caste")
                        .DisplayMember = "Desc"
                        .ReadOnly = False
                    End With
    
                End If
                rs.MoveNext()
            Loop
    
            dgvUserDetails.Columns.Add(col_Caste)
 
Posted 24-Dec-12 0:26am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you need to put
"Select d.caste from datafile d where d.AC_NO = " & cmbVidhanNo.Text & " "and d.caste is not null +  searchstring "
 
try that
  Permalink  
Comments
Rachna0309 at 24-Dec-12 7:05am
   
this will retrieve only those records where caste is not null..What I need is if it is not null,its value should be displayed in combobox when DGV loads else if it is null then all values from table should be filled in combobox to select.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Zoltán Zörgő 300
1 /\jmot 205
2 Peter Leow 165
3 CHill60 145
4 CPallini 135
0 Sergey Alexandrovich Kryukov 9,383
1 OriginalGriff 6,881
2 Peter Leow 4,607
3 Zoltán Zörgő 4,284
4 CHill60 2,892


Advertise | Privacy | Mobile
Web02 | 2.8.150129.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100