如何在datagridview的组合框中获取数据库值。 [英] How to get databse value in combobox of datagridview.

查看:95
本文介绍了如何在datagridview的组合框中获取数据库值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在datagridview中有10列,其中最后3列(种姓,教授,学位)是组合框。我的任务是如果数据库有这3个字段的值,它应该显示在grid的组合框中,否则应该添加空组合框以供用户选择值。添加组合框列的代码如下。可以任意1请帮助我。

I have 10 columns in datagridview out of which last 3 columns(caste,prof,degree) are combobox. My task is if database have value for these 3 fields,it should display in combobox of grid else empty combobox should be added for user to select value.Code to add combobox column is below.Can any1 please help me.

Dim con As OdbcConnection = New OdbcConnection
        sql = "Select Description 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 = "Description"
            .ReadOnly = False
        End With

        dgvUserDetails.Columns.Add(col_Caste)

推荐答案

添加项目模板你的gridview。

一旦完成,你就可以选择将它们链接到sql数据源或其他来源来获取记录。

传入一个sql选择命令。如果它没有返回任何东西,那么组合框将是空的
Add in a item template in your gridview.
Once that is done you would get options to link them to sql datasources or other sources to get the records.
Pass in a sql select command. if it doesnt return anything, then the combobox would be empty


这篇关于如何在datagridview的组合框中获取数据库值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆