开发者

Cannot change DataType of a column once it has data

开发者 https://www.devze.com 2023-02-17 21:48 出处:网络
I want to sort a gridview by a datetime-column so I need to change the datatype of that column I try it with following code but I\'m getting the error:

I want to sort a gridview by a datetime-column so I need to change the datatype of that column

I try it with following code but I'm getting the error:

dt.DefaultV开发者_如何学JAVAiew.Table.Columns["Meldingsdatum"].DataType = Type.GetType("System.DateTime");

dt.DefaultView.Sort = "Meldingsdatum asc";
gvOutlookMeldingen.DataSource = dt;
gvOutlookMeldingen.DataBind();


The error message tells you everything you need to know here; either (and preferred) make the column a DateTime initially (and importantly: before you load data), or hack around it. By which I mean perhaps add a second column (DateTime), and push the data accross - inefficient and extra work for no good reason.

0

精彩评论

暂无评论...
验证码 换一张
取 消