You must Sign In to post a response.
  • Category: ASP.NET

    How to Insert into Database Like this XXXJAN01-2016

    Hi Developers,

    Am tried many forums but i did not get correct answer.
    I want to insert a record like this format XXXJAN01-2016. this is january month.
    If February month is came the format will be XXX-FEB01-2016 ...., XXX-DEC01-2016.
    then continue with next year 2017.

    Please help me to i am dome this task Friends.

    Thanks with,
    Paul.S
  • #764211
    Hi Paul,

    What about datatype of that field?

    What is "XXX".?

    If the datatype is VARCHAR, then you can insert it without any issues.

    Please let me know the details.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764213
    Yes naveen Exactly that datatype is varchar, Please tell me any idea.

    thanks with
    Paul.S

  • #764214
    Hi Paul,


    Are you getting any error?

    If it's not saved as you want, then how it's saved?

    Please share that format.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764219
    Good morning Mr.Naveen.

    this is the Exact format CSWjan23-2016 which i am expecting.

    It does not throws any error, but the value is did not inserted properly.

    Thanks with
    Paul.S

  • #764222
    Thanks Mr.Naveen
    now I got the exact output Mr.naveen
    My code is :

    string dates = DateTime.Now.ToString("MMM d- yyyy");
    output is = Jan 23- 2016

    but instead of it i have to add prefix with it.

    Thanks with,
    Paul.S

  • #764224

    Hi
    try this code i added some changes in your code.



    string dates = "your string "+ DateTime.Now.ToString("MMM d- yyyy");
    output is = Jan 23- 2016



    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #764227
    Yes Mr.Kumar you are absolutely correct.

    But my prefefix value will be teh data which is already stored on the database. this is also no problem i can manage.

    But in this module i am using grid view dynamic textbox So only i get confused.

    If you know how to create dynamic textbox ROW and also how to insert the values into the database with validation.

    Please help me or refer some link is too
    Thanks with
    Paul.S

  • #764229

    It is bit customized logic, it looks in your format 'XXX' and 01 is constant, only Month and Year is variable
    you can achieve it using below C# sample
    With the help of 'now.ToString("MMM"));' method you can get month in expected format and with the help of 'now.ToString("yyyy")); you can get year in expected format
    so the final code is
    string szMonth = now.ToString("MMM"));
    string szYear = now.ToString("yyyy"));
    string finalString = "XXX-"+ szMonth + "01-" + szYear

    it will automatically increase when month and year changes.
    pl. ask me if you have any doubt in above sample


    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764236
    Hi,

    I guess your problem is resolved, if you still having any issues please let us know.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764241
    Yes Mr.Naveen my problem is solved.

    Thanks with
    Paul.S


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.