开发者

how to insert record into database on single button click from date to todate?

I have three textbox ... textbox1 and textbox2 and textbox3

I want when I choose from date in textbox1 say 1-May-2011 and to date in textbox2 say 30-May-2011 and in textbox I type 1,2,3,4,5

I want on button click ... event the values will be entererd in database from 1-May-2011 to 30-May2011 as : mentioned below :

开发者_C百科
DATABASE STRUCTURE


    ID       Date               Items
    1        1-May-2011         1,2,3,4,5
    2        2-May-2011         1,2,3,4,5
    3        3-May-2011         1,2,3,4,5

so on till 30_may-2011

Record will be inserted in database according to from date and to date choosen in textbox1 and textbox2 respectively ...

How to resolve this ?


If it is acceptable for your solution, then the easiest way is to construct all the data for insertion and then insert them all (it will cause a number of inserts). This is what Ranhiru Cooray has suggested in his answer - just iterate through all dates, construct each row and call insert for each of them.

BUT, if you want to do it by one DB call, then I would suggest creating a stored procedure in database, which gets these 3 parameters and then executes inserts inside it - by constructing insertion rows inside itself and executing each of them - still remaining in bounds of a single database call for your code or application.

I hope this helps!


DateTime start = DateTime.Parse("1/1/2010");
DateTime end = DateTime.Parse("1/30/2010");

        while(start <= end)
        {
            Console.WriteLine("Date : " + start.ToShortDateString());
            start = start.AddDays(1);
        }

This will help you get started :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜