本文介绍了如何从数据库获取datagridview的comboboxcolumn值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我 comboboxcolumn datagridview 。我 想要 display value in grid if its value database 表 不 null 。例如 one 列 caste 。 if 此 null my databse 表 然后 combobox column 已添加 至 grid else caste value shold 见 combobox datagridview 加载 .. any1 help me 。 my code: Dim cast 作为 整数 = 0 Dim con As OdbcConnection = 新 OdbcConnection sql = 从数据文件d中选择d.caste,其中d.AC_NO =& cmbVidhanNo.Text& + searchstring If rs.State = 1 然后 rs.Close() rs.Open(sql, MainCon, 1 , 3 ) 虽然 不 rs.EOF 如果 不 IsDBNull(rs.Fields( 0 )。值)然后 cast = rs.Fields( 0 )。值 结束 如果 如果 不 IsDBNull(强制转换)然后 使用 col_Caste .Name = Caste .HeaderText = Caste .DataPropertyName = cast 。 ReadOnly = False 结束 使用 其他 sql = 从类别中选择描述,其中Catgry = 1 con。 ConnectionString = connstring 如果 con.State = ConnectionState.Open 那么 con.Close() con.Open() Dim da As OdbcDataAdapter = 新 OdbcDataAdapter(sql,con) da.Fill(ds, Caste ) 使用 col_Caste .Name = Caste .HeaderText = Caste .DataSource = ds.Tables( Caste) .DisplayMember = Desc 。 ReadOnly = False 结束 使用 结束 如果 rs.MoveNext() 循环 dgvUserDetails.Columns.Add(col_Caste) 解决方案 你需要把 从数据文件d中选择d.caste,其中d.AC_NO =& cmbVidhanNo。文字& 和 d.caste 不 null + searchstring 尝试 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) 解决方案 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 这篇关于如何从数据库获取datagridview的comboboxcolumn值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 00:50