Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am trying to pass a dataSet object to a method to generate a comboBox with the DataSet Values the code is :

method Code:

      public static DataGridViewComboBoxColumn generateGridViewComboBoxColumn(String _propertyName, String _displayMember,String _valueMember
        ,DataSet _ds,String _tableName) {

        DataGridViewComboBoxColumn generatedCB = new DataGridViewComboBoxColumn();
        generatedCB.DataPropertyName = _propertyName; /*campo del que va a generar el comboBox| en caso de usar sql seria el nombre del campo de la tabla*/
        generatedCB.DisplayMember = _displayMember;/*nombre que a visualizar en el combo box*/
        generatedCB.ValueMember = _valueMember;/*valores que va a guardar en el combo box una vez selecionemos el objeto visualizado*/
        generatedCB.DataSource = _ds.Tables[_tableName];/*origen de los datos del combobox*/
        return generatedCB;
    }

the call to the method:

 cmbCodLigas=Utils.generateGridViewComboBoxColumn("CODLIGA", "NOMLIGA", "CODLIGA", ds, "ligas");

Dataset code

 public partial class ComboDentroDataGrid : Form
{
    DataSet ds = new DataSet();
    SqlDataAdapter daLigas;
    SqlDataAdapter daEquipos;
    

    public ComboDentroDataGrid()
    {
        InitializeComponent();
    }

    private void ComboDentroDataGrid_Load(object sender, EventArgs e)
    {   /*abrimos la conexion*/
        Conexion conexion = new Conexion();
        conexion.Con.Open();
        /*generamos las consultas*/
        String selectLigas = "select * from T_LIGAS";
        /*para a?adir el combo box  cambio la consulta un poco*/
        String selectEquipos = "select * from T_EQUIPOS";
        /*configuramos ligas*/
        daLigas = new SqlDataAdapter(selectLigas, conexion.Con);
        daLigas.Fill(ds, "ligas");
        ligasGridView.DataSource = ds.Tables["ligas"];
        daEquipos = new SqlDataAdapter(selectEquipos, conexion.Con);
        daEquipos.Fill(ds, "equipos");
        equiposGridView.DataSource = ds.Tables["equipos"];
        /*creamos el comboBox*/
        DataGridViewComboBoxColumn cmbCodLigas = new DataGridViewComboBoxColumn();

my problem is that i am not getting a error but still the dataSet is empty and i dont know why. thx in advance

question from:https://stackoverflow.com/questions/66054178/passing-dataset-to-a-method

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
93 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...