Hi,

I populate a datagridview with ( select a,b,c from ....) so this is my datatable, but I have more column on the grid < d,e,f > and I edit those columns which are not defined in datatable ( d,e,f) and when I update a,b,c inserted but d,e,f are not. That is probably those additional columns are not bound. So do I have to define those columns to dataset and datatable first and if so how do I do it.

Thanks,

snky

serkan sendur commented: na -2

Recommended Answers

All 3 Replies

Yes you need to define them. Are you using a typed dataset or an in memory data table/dataset?

It's an in memory one. I haven't done enough reading and studying for typed dataset. I recall you advising to use it. I will do it soon
snky

ds = new DataSet();
da.Fill(ds, "Izin");
tb = ds.Tables[0];

bindingSource1.DataSource = ds.Tables[0];
tblIzinDokum.DataSource = bindingSource1;


if (rbNewRecord.Checked == true)
                    {
     //  Manually create columns and assign values in the datatable
                        

                        DataColumn colHakedis = new DataColumn("hakedis_tarihi");
                        colHakedis.DataType = System.Type.GetType("System.DateTime");


                        DataColumn colIzintipi = new DataColumn("izin_tipi");
                        colHakedis.DataType = System.Type.GetType("System.String");

                        DataColumn colSuaizni = new DataColumn("sua");
                        colHakedis.DataType = System.Type.GetType("System.Int32");

                        tb.Columns.Add(colHakedis);
                        tb.Columns.Add(colIzintipi);
                        tb.Columns.Add(colSuaizni);

                        foreach (DataRow dRow in tb.Rows)
                        {
                            dRow.BeginEdit();
                            dRow["hakedis_tarihi"] = DateTime.Parse(Convert.ToString(Izindate).ToString()).ToShortDateString();
                            dRow["izin_tipi"] = "Yıllık İzin";                                                
                            dRow["sua"] = 30;
                        //to flag each line as New first change the Row
                        //Status to UnChanged 
                        dRow.AcceptChanges();
                        //Then mark the status as new line to insert
                        dRow.SetAdded();
                                    
                        }

// For Datagridview


foreach (DataGridViewRow r in tblIzinDokum.Rows)
                        {
                            if (r.IsNewRow)
                                continue;

                            
                            DateTime dt = Convert.ToDateTime(r.Cells["colBaslama"].Value);
                            TimeSpan MyDays = (Convert.ToDateTime(dfDegerTarih.Text)).Subtract(dt);

                            int MyYears = MyDays.Days / 365;
                            int IzinYil = ((Convert.ToDateTime(dfDegerTarih.Text)).Year) - ((dt).Year);
                            if (MyYears >= 1)
                            {
                                DateTime Izindate = dt.AddMonths(12).Date;
 
                                r.Cells["colHaktarih"].Value = DateTime.Parse(Convert.ToString(Izindate).ToString()).ToShortDateString();
                                r.Cells["colIzinTipi"].Value ="Yıllık İzin";

                                r.Cells["colSuaizni"].Value = 30;

So 3 column which are originally populated into dataset and therefore to datagridview are inserted. The other 3 columns which I try to manupulate above cannot be inserted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.