1
Answer

How to create month columns in database basedon no.of months

madhu goud

madhu goud

9y
374
1
i have
No of months
Start date
end date  in my page
 
when i give number of months 3 and start date 10/7/2015 then end date will calculated to 10/9/2015 automatically.
 
And now i want to create extra columns in database i.e June-2015, july and august
in this table or another table 
 
how to create month columns automatically based on Number months and start date,end date  
 
 
my code is 
 
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("Insert into monthcal (NoOfMonths,StartDate,EndDate) values (@NoOfMonths,@StartDate,@EndDate)", con);
cmd.Parameters.AddWithValue("@NoOfMonths", txtNoOfMonths.Text.ToString());
cmd.Parameters.AddWithValue("@StartDate", txtStartDate.Text.ToString());
cmd.Parameters.AddWithValue("@EndDate", txtEndDate.Text.ToString());
con.Open();
cmd.ExecuteNonQuery();
}
 
protected void txtStartDate_TextChanged(object sender, EventArgs e)
{
string inputString = txtStartDate.Text;
DateTime dt = DateTime.ParseExact(inputString, "yyyy/MM/dd", CultureInfo.InvariantCulture);
dt = dt.AddMonths(Convert.ToInt32(txtNoOfMonths.Text));
txtEndDate.Text = dt.ToString("yyyy/MM/dd");
DateTime Date1 = Convert.ToDateTime(txtStartDate.Text);
DateTime Date2 = Convert.ToDateTime(txtEndDate.Text);
//int Datediff = ((Date2.Year - Date1.Year) * 12) + Date1.Month - Date2.Month;
int DayDiff = (Date2.Date - Date1.Date).Days;
Label1.Text = "Total days" + " " + (DayDiff.ToString());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Answers (1)
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 7y
What is exact issue: either you are not display the table with rows or displaying but on click of radio button nothing working. Please describe more.
0
Ram Chan

Ram Chan

NA 73 8 7y

Kindly refer this   

 
ASP.NET MVC: Intro to MVC using Binding JSON objects to Models

using System;

namespace bindingJSON

{

public class Squirrel

{

public string Name { get; set; }

public int? Age { get; set; } // squirrels aren't required tell us their age

public int Acorns { get; set; }

public char Gender { get; set; }

public string Hobby { get; set; }

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

namespace bindingJSON.Controllers

{

public class HomeController : Controller

{

public ActionResult Index()

{

// Initial View

return View();

}

[HttpPost]

public JsonResult PostSquirrel(Squirrel incomingSquirrel)

{

string status = null;

try {

saveSquirrel(incomingSquirrel);

status = "If you don't see this, something went wrong.";

} catch (Exception e) {

status = e;

}

return Json(status);

}

#region privateHelpers

private Boolean saveSquirrel(Squirrel incomingSquirrel)

{

if (!incomingSquirrel.Age) {

// do something...

return false;

} else {

// do something positive!

return true;

}

}

#endregion

}

}

@model bindingJSON.Squirrel

@{

Layout = null;

}

<!DOCTYPE html>

<html lang="en">

<head>

<title>Index</title>

</head>

<script type="text/javascript" src="https://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

// when the DOM has fully loaded...

$("#btnSubmit").bind("click", function() {

var onEventLaunchSquirrel = new postSquirrel();

onEventLaunchSquirrel.launchSquirrel();

});

});

function postSquirrel() {

this.launchSquirrel = function() {

// fetch values from input

var name = $("Name").val();

var age = $("Age").val();

var acorns = $("Acorns").val();

var gender = $("Gender").val();

var hobby = $("Hobby").val();

// build json object

var squirrel = {

Name: name,

Age: age,

Acorns: acorns,

Gender: gender,

Hobby: hobby

};

$.ajax({

type: "POST",

url: "home/PostSquirrel",

traditional: true,

contentType: 'application/json; charset=utf-8',

data: JSON.stringify(squirrel),

success: function (data) { console.log(data) },

error: function (data) { console.log(data) }

});

}

}

</script>

<body>

<header>

<hgroup>

<h1>oh hey, a squirrel!</h1>

<h3>we should interview it!</h3>

</hgroup>

</header>

<section>

<p>If the squirrel cooperates, record their information and send it to our server.</p>

<p><input type="text" required="required" id="Name" placeholder="Enter the squirrel's name" /></p>

<p><input type="number" id="Age" placeholder="squirrel's age (optional)" /></p>

<p><input type="number" required="required" id="Name" placeholder="How many acorns do they own?" /></p>

<p><input type="number" required="required" id="Name" placeholder="M or F? (single letter only)" size="1" /></p>

<p><input type="string" required="required" id="Hobby" placeholder="How many acorns do they own?" /></p>

<p><input id="btnSubmit" type="button" value="launch the squirrel through the internet!" /></p>

<div id="status"></div>

</section>

</body>

</html>

0
Krishna Rajput Singh

Krishna Rajput Singh

NA 5.5k 2m 7y
Hi mahesh thank you for writing below links helpful for you.
 
 
https://www.aspsnippets.com/Articles/Pass-value-from-child-popup-window-to-parent-page-window-using-JavaScript.aspx
 
https://stackoverflow.com/questions/32508072/pass-parameters-to-popup-window-from-button-mvc
 
http://www.c-sharpcorner.com/UploadFile/krishnasarala/popup-windows-in-Asp-Net-mvc/