Unable to cast object of type 'System.Int32' to type 'System.String' in DataReader.GetString()

后端 未结 4 509
Happy的楠姐
Happy的楠姐 2020-12-11 04:21

I was trying to add data from a database to acombobox.

        try
        {
            SqlCeCommand com = new SqlCeCommand(\"select * from Category_Master\         


        
4条回答
  •  清歌不尽
    2020-12-11 04:41

    Use Column name in your query then specify that column name into the reader.

    SqlCeCommand com = new SqlCeCommand("select catg from Category_Master", con);
                    SqlCeDataReader dr = com.ExecuteReader();
                    while(dr.Read()){
                        string name = dr("catg").ToString();
                        cmbProductCategory.Items.Add(name);
                    }
    

提交回复
热议问题