First application will be named
HelloWorld
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json",
data: "{}",
url: "Default.aspx/GetEvents",
dataType: "json",
success: function (data) {
$('div[id*=fullcal]').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: $.map(data.d, function (item, i) {
var event = new Object();
event.id = item.EventID;
event.start = new Date(item.StartDate);
event.end = new Date(item.EndDate);
event.title = item.EventName;
event.url = item.Url;
event.ImageType = item.ImageType;
return event;
}), eventRender: function (event, eventElement) {
if (event.ImageType) {
if (eventElement.find('span.fc-event-time').length) {
eventElement.find('span.fc-event-time')
.before($(GetImage(event.ImageType)));
} else {
eventElement.find('span.fc-event-title')
.before($(GetImage(event.ImageType)));
}
}
},
loading: function (bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
}
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;
}
});
$('#loading').hide();
$('div[id*=fullcal]').show();
});
function GetImage(type) {
if (type == 0) {
return "<br/><img src = 'Styles/Images/attendance.png' style=
'width:24px;
height:24px'/><br/>";
}
else if (type == 1) {
return "<br/><img src = 'Styles/Images/not_available.png' style=
'width:24px;
height:24px'/><br/>";
}
else
return "<br/><img src = 'Styles/Images/not_available.png' style=
'width:24px;
height:24px'/><br/>";
}
</script>
[WebMethod]
public static IList GetEvents()
{
IList events = new List<Event>();
for (int i = 0; i < DateTime.DaysInMonth(DateTime.Now.Year,
DateTime.Now.Month); i++)
{
events.Add(new Event
{
EventName = "My Event " + i.ToString(),
StartDate = DateTime.Now.AddDays(i).ToString("MM/dd/yyyy"),
EndDate = DateTime.Now.AddDays(i+1).ToString("MM/dd/yyyy"),
ImageType = i % 2,
Url = @"http://www.google.com"
});
}
return events;
}
public class Event
{
public Guid EventID { get { return new Guid(); } }
public string EventName { get; set; }
public string StartDate { get; set; }
public string EndDate { get; set; }
public int ImageType { get; set; }
public string Url { get; set; }
}
<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<center>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" Width="1000" />
</center>
</form>
</body>
</html>
Adding Csharp ( C# ) Code
- Now go to Csharp code of New Added Webform and Add code similar to code below :-
- Add this code under your partial class --
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"));
Customers dsCustomers = GetData("select * from Testtable");
crystalReport.SetDataSource(dsCustomers);
CrystalReportViewer1.ReportSource = crystalReport;
}
private Customers GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}
Public Class Form1
Dim connection As New OleDbConnection
Dim command As New OleDbCommand
Dim ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\test.mdb
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connection.ConnectionString = ConnectionString
connection.Open()
End Sub
Now in this block of code we have initialized our OledbConnection instance with connection string variable that we have initialized in previous step. So in this code we have given the Oledbconnectin instance means connection some information about Provider to use and location of database file on computer
Then we have used connection.open() method opens port for Enter into Access Database. this opens a pipe to execute query in database
How To Use Access database with vb.net
Difference Between MVC and webforms |