Click here to Skip to main content
12,350,121 members (26,817 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
my code is not executed so what is the problem of my code please check...

Imports System.IO
Imports System.Data.SqlClient
Imports System.Windows.Forms.DataVisualization.Charting
 

Public Class Form1
    Dim con As New SqlConnection
    Dim str As String
    Dim rsTemp As DataTable
    Dim a(1), ln As Integer
    Dim qury As New SqlCommand
    Dim sqldr As New SqlDataAdapter
 

 
    Private Sub btnshow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnshow.Click
        ' Try

        str = "Data Source=PROJECT\SQLEXPRESS;Initial Catalog=tt;User ID=base;Password=base"
        con = New SqlConnection(str)
        con.Open()
        qury = New SqlCommand("Delete from Time_1", con)
 
        qury.ExecuteNonQuery()
        con.Close()
        Dim da As New SqlDataAdapter
        Dim cb As New SqlCommandBuilder
        Dim dttemp As DataTable
        dttemp = New DataTable
        ' da = New SqlDataAdapter("select Count(*) as Temperature ,TTime from Time_1 where  month(TTime)=" & Month(dtpfrom.Value) & " and year(TTime)=" & Year(dtpfrom.Value) & " group by TTime order by TTime", str)
        da = New SqlDataAdapter("select * from Time_2  where  month(TimeStamp)=" & Month(dtpfrom.Value) & " and year(TimeStamp)=" & Year(dtpfrom.Value) & " group by TimeStamp,Tagref,value order by TimeStamp", str)
        cb = New SqlCommandBuilder(da)
        da.Fill(dttemp)
 
        Dim c As Integer
        c = dttemp.Rows.Count
 

        Dim vUCL(c), vLCL(c), v6s(c), v3s(c), v6s1(c), v3s1(c), vCL(c) As Object
        Dim x, x1 As Double
        Dim Arr(c) As Single
        Dim avg, avg1 As Double
 
        Dim Average(c) As Single
        Dim Std_Dev(c) As Single
        Dim i As Long
        i = 1
 
        For Each row As DataRow In dttemp.Rows
            Arr(i) = row.Item(2)
 
            i = i + 1
        Next
 
        For Each row As DataRow In dttemp.Rows
            avg = avg + row.Item(2)
        Next
        avg1 = avg / c
 

        For i = 1 To c
            Average(i) = Mean(i, Arr)
            Std_Dev(i) = StdDev(i, Arr)
            x = 3 * Std_Dev(i)
            x1 = 6 * Std_Dev(i)
 
            con = New SqlConnection(str)
            con.Open()
            qury = New SqlCommand("insert into time_1 values('" & dttemp(i - 1).Item(0) & "','" & Arr(i) & "','" & x1 & "','" & x & "','" & avg1 & "','" & (-x) & "','" & (-x1) & "')", con)
 
            qury.ExecuteNonQuery()
            con.Close()
 

        Next
        Dim da1 As New SqlDataAdapter
        Dim cb1 As New SqlCommandBuilder
        Dim dttemp1 As DataTable
        dttemp1 = New DataTable
 
        ' da1 = New SqlDataAdapter("select * from Time_1  where  month(TTime)=" & Month(dtpfrom.Value) & " and year(TTime)=" & Year(dtpfrom.Value) & " group by  TTime, Temperature, [+6S], [+3S], CL, [-3S], [-6S] order by TTime", str)
        da1 = New SqlDataAdapter("SELECT convert(varchar,TTime,108) as TTime, Temperature,  CL FROM dbo.Time_1", str)
        cb1 = New SqlCommandBuilder(da1)
        da1.Fill(dttemp1)


MSChart1.DataSource = dttemp1
MSChart1.Series(0).XValueMember = "TTime" 'values for X axis
MSChart1.Series(0).YValueMembers = "Temperature"
MSChart1.Series(1).XValueMember = "TTime"
MSChart1.Series(1).YValueMembers = "Temperature"
MSChart1.Series(2).XValueMember = "TTime"
MSChart1.Series(2).YValueMembers = "Temperature"
MSChart1.Series(3).XValueMember = "TTime"
MSChart1.Series(3).YValueMembers = "Temperature"


MSChart1.DataBind()
Dim dblMean As Double = MSChart1.DataManipulator.Statistics.Mean("Temp") 'uses datamanipulator to return mean

'lblAveSales.Text = Format(dblMean, "0.00")
Dim lstDates As New List(Of Date)
Dim lstValues As New List(Of Double)
Dim intTotalUnitsSold As Integer = 0
For i1 As Integer = 0 To dttemp1.Rows.Count - 1
intTotalUnitsSold += dttemp1.Rows(i1).Item(1)
lstDates.Add(dttemp1.Rows(i1).Item(0))
lstValues.Add(dttemp1.Rows(i1).Item(1))
'lstValues.Add(dblMean)

Next
MSChart1.Series(0).Points.DataBindXY(lstDates.ToArray, lstValues.ToArray)

Dim dblMean1 As Double = MSChart1.DataManipulator.Statistics.Mean("CL") 'uses datamanipulator to return mean
'lblAveSales.Text = Format(dblMean, "0.00")
Dim lstDates1 As New List(Of Date)
Dim lstValues1 As New List(Of Double)
Dim intTotalUnitsSold1 As Integer = 0
For i1 As Integer = 0 To dttemp1.Rows.Count - 1
intTotalUnitsSold1 += dttemp1.Rows(i1).Item(2)
lstDates1.Add(dttemp1.Rows(i1).Item(0))
lstValues1.Add(dttemp1.Rows(i1).Item(2))

Next
MSChart1.Series(1).Points.DataBindXY(lstDates1.ToArray, lstValues1.ToArray)
If dttemp.Rows.Count > 0 Then
           c = dttemp.Rows.Count
       Else
           MsgBox("Records not found for the month and year of " & Format(dtpfrom, "MMM-yyyy"), vbInformation, "No Records")
           Exit Sub
       End If

Dim vData(,) As Object
      'ReDim vData(c + 1, c + 2)
      ReDim vData(c, 8)
i = 1
        ' While rsTemp.EOF = False
        For Each row As DataRow In dttemp.Rows
            Arr(i) = row.Item(2)
            '    '  dt(i) = row.Item(0)
            i = i + 1
        Next
 
        '  rsTemp.MoveNext()
        ' End While

        For i = 1 To c
            Average(i) = Mean(i, Arr)
            Std_Dev(i) = StdDev(i, Arr)
            x = 3 * Std_Dev(i)
            x1 = 6 * Std_Dev(i)
 
            con = New SqlConnection(str)
            con.Open()
            qury = New SqlCommand("insert into time_1 values('" & dttemp(i - 1).Item(0) & "','" & Arr(i) & "','" & x1 & "','" & x & "',0,'" & (-x) & "','" & (-x1) & "')", con)
 
            qury.ExecuteNonQuery()
            con.Close()
 

        Next
        ' MessageBox.Show("---------")

        For i = 1 To c
            vUCL(i) = Average(i) + (2.66 * Std_Dev(i))
            vLCL(i) = Average(i) - (2.66 * Std_Dev(i))
Next
Dim dblMean2 As Double = MSChart1.DataManipulator.Statistics.Mean("UCL") 'uses datamanipulator to return mean
'lblAveSales.Text = Format(dblMean, "0.00")
Dim lstDates2 As New List(Of Date)
Dim lstValues2 As New List(Of String)
Dim intTotalUnitsSold3 As Integer = 0
For i1 As Integer = 0 To dttemp1.Rows.Count - 1
'intTotalUnitsSold3 += dttemp1.Rows(i1).Item(3)
lstDates2.Add(dttemp1.Rows(i1).Item(0))
lstValues2.Add(vUCL.ToString)
Next
MSChart1.Series(2).Points.DataBindXY(lstDates2.ToArray, lstValues2.ToList)

Dim dblMean3 As Double = MSChart1.DataManipulator.Statistics.Mean("LCL") 'uses datamanipulator to return mean
'lblAveSales.Text = Format(dblMean, "0.00")
Dim lstDates3 As New List(Of Date)
Dim lstValues3 As New List(Of String)
Dim intTotalUnitsSold4 As Integer = 0
For i1 As Integer = 0 To dttemp1.Rows.Count - 1
' intTotalUnitsSold4 += dttemp1.Rows(i1).Item(3)
lstDates3.Add(dttemp1.Rows(i1).Item(0))
lstValues3.Add(vLCL.ToString)
Next
MSChart1.Series(3).Points.DataBindXY(lstDates3.ToArray, lstValues3.ToList)
End Sub
 
   Function Mean(ByVal k As Long, ByVal Arr() As Single)
       Dim Sum As Single
       Dim i As Integer
 
       Sum = 0
       For i = 1 To k
           Sum = Sum + Arr(i)
       Next i
 
       Mean = Sum / k
 
   End Function
 
   Function StdDev(ByVal k As Long, ByVal Arr() As Single)
       Dim i As Integer
       Dim avg As Single, SumSq As Single
 
       avg = Mean(k, Arr)
       For i = 1 To k
           SumSq = SumSq + (Arr(i) - avg) ^ 2
       Next i
       If k > 1 Then
           StdDev = Math.Sqrt(SumSq / (k - 1))
       End If
       'Return StdDev
   End Function

End class
Posted 19-Jan-12 17:26pm
Comments
Scubapro 20-Jan-12 4:38am
   
Use a try 'routine' and pinpoint the location of your problem. Then show us the code of were you're stuck.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 19 Jan 2012
Copyright © CodeProject, 1999-2016
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