Click here to Skip to main content
11,429,154 members (68,179 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 23:58pm
hspl239
Comments
owencampbell at 21-Jan-13 5:35am
   
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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
v2
Comments
hspl at 21-Jan-13 6:43am
   
Thanks sir for your solution, if you don't mind can tell me how can save the above record in database
OriginalGriff at 21-Jan-13 6:55am
   
Answer updated
hspl at 21-Jan-13 7:34am
   
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 at 21-Jan-13 7:46am
   
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 at 21-Jan-13 8:08am
   
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 at 21-Jan-13 8:20am
   
It's an example. You are supposed to modify it to fit your circumstances...
hspl at 21-Jan-13 9:21am
   
Sorry sir.....i am unable to solve....thanks for your helps.
OriginalGriff at 21-Jan-13 9:29am
   
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 at 21-Jan-13 9:43am
   
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 at 21-Jan-13 10:26am
   
Yes. And?
What part is giving you problems?
Because you have all the bits you need - you just need to fit them together.
hspl at 21-Jan-13 10:44am
   
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 at 21-Jan-13 11:00am
   
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 at 21-Jan-13 11:18am
   
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)



Advertise | Privacy | Mobile
Web04 | 2.8.150428.2 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100