Click here to Skip to main content
Sign Up to vote bad
good
See more: VB.NET
Dear Sir,
 
How can i do this:-
 
I have two text boxes one for Enter Month and another How many user want to add
after that.
 
Enter Month :-
How many Add After Above Month:-
 
Let say if user enter January on first Text Box and want to add 4 more months
after January by enter 4 on next Text Box, how can i do that, i also saved the data
on database.
 
Rgds,
Indranil
Posted 20 Jan '13 - 22:58
hspl239

Comments
owencampbell - 21 Jan '13 - 5:35
Hi, I'd personally rethink the controls you are using as allowing the user to enter manual text will cause you all sorts of problems. I don't understand from your description what it is your after as a final result but I'd change your first text-box control to either a DropDown or Calendar control and your 2nd text-box to a NumericUpDown control. Changing your control will allow you to read in the user selection easier and then do your required work-in out. You may also want to think about rolling round if you selected December and added 4. Cheers,

1 solution

The first thing to do is convert the users input to a DateTime - probably you want to use DateTime.TryParseExact to do that.
You can then use the DateTime.AddMonths method to get the new date, and store that as a DateTime in the database.
Dim [date] As String = "February"
Dim addMonths As String = "4"
Dim dt As DateTime
If DateTime.TryParseExact([date], "MMMM", CultureInfo.InvariantCulture, DateTimeStyles.None, dt) Then
    Dim i As Integer
    If Integer.TryParse(addMonths, i) Then
        dt = dt.AddMonths(i)
        ...
    End If
End If
 

"Thanks sir for your solution, if you don't mind can tell me how can save the above record in database"
 
That bit I can't help you with - there are too many different database systems and table / column combinations for me to give you a simple answer.
However a simple method using a SQL Database would be along the lines of:
 
                Using con As New SqlConnection(strConnect)
                	con.Open()
                	Using com As New SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con)
                		com.Parameters.AddWithValue("@C1", myValueForColumn1)
                		com.Parameters.AddWithValue("@C2", myValueForColumn2)
                		com.ExecuteNonQuery()
                	End Using
                End Using
But since I do not know any of your details, you will have to fill them in yourself!
  Permalink  
Comments
hspl - 21 Jan '13 - 6:43
Thanks sir for your solution, if you don't mind can tell me how can save the above record in database
OriginalGriff - 21 Jan '13 - 6:55
Answer updated
hspl - 21 Jan '13 - 7:34
Thanks again for your reply, i want to give you the details about my database please help me......... Using ms access database name indra.mdb, where i used a LOAN table the details are given below :- Code,Mem_Id,Mem_Name,Dt_Loan,Loan_Amt,Month_LoanPay,Amt_Pay,Period. This the details now please tell me how can i save the record in database.
OriginalGriff - 21 Jan '13 - 7:46
Ok, you are using Access so replace SqlConnection and SqlCommand with OleDbConnection and OleDbCommand, provide your connection string as strConnect. Then put "Loan" in place of "myTable" and replace "myColumn1" and "myColumn2" with a comma separated list of your fields: Code,Mem_Id,Mem_Name,Dt_Loan,Loan_Amt,Month_LoanPay,Amt_Pay,Period Then replace "@C1, @C2" with short forms of each of those fields ("@CODE", "@MNAME" and so on). Then create one line per field with the AddWithValue statement, using the short form you created above, and the name of the variable holding the information. It's only typing, it's not difficult!
hspl - 21 Jan '13 - 8:08
Ok, but were i will use this below statement by which i save the record in database Dim [date] As String = "February" Dim addMonths As String = "4" Dim dt As DateTime If DateTime.TryParseExact([date], "MMMM", CultureInfo.InvariantCulture, DateTimeStyles.None, dt) Then Dim i As Integer If Integer.TryParse(addMonths, i) Then dt = dt.AddMonths(i) ... End If End If
OriginalGriff - 21 Jan '13 - 8:20
It's an example. You are supposed to modify it to fit your circumstances...
hspl - 21 Jan '13 - 9:21
Sorry sir.....i am unable to solve....thanks for your helps.
OriginalGriff - 21 Jan '13 - 9:29
What part can you not do yourself? Do be aware, that this is your homework, not mine, so I will be expecting you to actually do most of the work! But I'll help you through...
hspl - 21 Jan '13 - 9:43
Sir...below i want to do.... i want to generate months after selecting the month form combobox(i changed it from textbox)say in combobox i select JANUARY, and amount of payment in Amt_pay textbox, the logic is if x member take loan and want to repay it from January till it loan becomes 0.
OriginalGriff - 21 Jan '13 - 10:26
Yes. And? What part is giving you problems? Because you have all the bits you need - you just need to fit them together.
hspl - 21 Jan '13 - 10:44
Actually i want to do... I want to issue advance to employee and this advance will be deducted from his salary by the MONTH he want to refund his advance for example :- If the employee X has taken advance in the month of January 2012 and he wants to return his advance in installments by the month of MARCH (NOT FROM THE MONTH OF JANUARY OR FEBRUARY) 2012. What I wanted to do that when the salary of the Mr. X is being generated for the month of MARCH 2012 the software should start deducting installment amount from his salary from the month of MARCH 2012 till his advance becomes 0 Please help me on above problem.....how to design my form as well as database etc.
OriginalGriff - 21 Jan '13 - 11:00
Start with the form. What information does it need to have? Try doing the job on paper and see what info you need to do it. That kinda defines what you need on your form (and what you need in your database).
hspl - 21 Jan '13 - 11:18
Ok Sir........let me create the form along with database.....then i will give you what i create, than we move....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 508
1 Arun Vasu 275
2 Maciej Los 238
3 OriginalGriff 215
4 Mahesh Bailwal 200
0 Sergey Alexandrovich Kryukov 9,660
1 OriginalGriff 7,329
2 CPallini 3,968
3 Rohan Leuva 3,339
4 Maciej Los 2,851


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid