刷新网站时如何避免重复数据库中的数据?

时间:2015-01-11 16:36:12

标签: jquery asp.net vb.net sql-server-2008

我从这个fullcalender网站获得了输出,但是当我刷新网站时,相同的数据仍然被添加到这个fulcalender。如何解决这个问题?

Public Shared Function GetEvents() As IList    
        Try
        Dim sqlCS As String = "Data Source=" & DatabaseServerName & ";initial catalog=" & DatabaseCatalog & ";User ID=" & DatabaseServerUser & ";PASSWORD=" & DatabaseServerPass
        SqlCn = New SqlClient.SqlConnection
        SqlDA = New SqlClient.SqlDataAdapter
        SqlCn.ConnectionString = sqlCS
        If SqlCn.State = ConnectionState.Closed Then SqlCn.Open()
        SqlCMD = New SqlCommand("SELECT distinct Cust_FNameA, Cust_dob  FROM NewCus where DATEDIFF(DAY, GETDATE(), DATEADD(YEAR, DATEDIFF(YEAR, Cust_dob, GETDATE()), Cust_dob)) BETWEEN 0 AND 30", SqlCn)
        SqlDA.SelectCommand = SqlCMD
        SqlDA.Fill(dt2)
        Dim events As IList = New List(Of [Event])

        For k As Integer = 0 To DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)
            events.Clear()

            HttpContext.Current.Session("mydata") = dt2
            Dim dtt As DataSet = DirectCast(HttpContext.Current.Session("mydata"), DataSet)
            For Each r As DataRow In dtt.Tables(0).Rows

                Dim dt As DateTime = CDate(r("Cust_dob")).ToString("MM-dd")
                Dim s As String = dt.Day.ToString()
                Dim s1 As String = dt.Month.ToString()

                If DateTime.Now.AddDays(k).ToString("MM-dd") = dt Then

                    events.Add(New [Event]() With { _
                     .EventName = r("Cust_FNameA").ToString() + " _ " + "عيد ميلاد", _
                     .StartDate = DateTime.Now.AddDays(k).ToString("MM-dd-yyyy"), _
                     .EndDate = DateTime.Now.AddDays(1).ToString("MM-dd-yyyy") _
        })

                End If
            Next
        Next
        Return events
    Catch ex As Exception
    Finally
        SqlCMD.Dispose()
        SqlDA.Dispose()
    End Try

    $(document).ready(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json",
            data: "{}",
            url: "FullCalender.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>
<div id="loading">`enter code here`
    <img src="../images/loading_wh.gif" />
</div>
<div id="fullcal">
</div>

我该如何克服这个问题?如何避免覆盖数据?

1 个答案:

答案 0 :(得分:0)

尝试禁用缓存,将其附加到$ .ajax调用:

    cache: false

另见:http://api.jquery.com/jquery.ajax/