开发者

Save data with LINQ

I've create object with data type: DateTime But I want save as char data type in sql server

ex: assign value to obj property: MyDateTime=DateTime.Now; //when use to string method result: MM/dd/yyyy hh:mm:ss //save to db MyDateTime column with data type char(12) we will save: MM/dd/yyyy

How can I save it. I try use assign converter attribute to property but does not effect

Update: 2010/09/24 13:36 Ex:

DataContext data=new DataContext();

MyObject obj=new MyObject();

obj.MyDate=DateTime.Now;

data.开发者_如何学GoMyObjects.InsertOnSubmit(obj);

data.SubmitChange();

property's data type of object is: DateTime

column in db is char(12)

how can I format it or write custom attribute to format data before save to db


Use a string formatter:

string dateString = MyDateTime.ToString("MM/dd/yyyy");

And write that value to the Database.

For other examples, have a look here:

http://www.csharp-examples.net/string-format-datetime/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜