I tried below code to generate the stacked chart but I can't get the desired output.
I want the chart output is based on the datatable output.
What is wrong with my code? :(

conn.Open()

            mySelect = "SELECT REFLINKTBL.LINENAME, MCNAME, JSFACTOR.EVENTTM "
            mySelect = mySelect & " FROM (SELECT JSLINE.LINENAME, JSMC.RECID, JSMC.MCNAME, JSMC.GOH "
            mySelect = mySelect & " FROM JSLINE RIGHT OUTER JOIN  "
            mySelect = mySelect & " JSMC ON JSLINE.RECID = JSMC.ID_JSLINE) REFLINKTBL INNER JOIN  "
            mySelect = mySelect & " JSFACTOR ON JSFACTOR.ID_JSMC = REFLINKTBL.RECID  "
            mySelect = mySelect & " WHERE JSFACTOR.YOUIN LIKE '%PARTSC%' "
            mySelect = mySelect & "  AND LINENAME LIKE 'M%' "
            mySelect = mySelect & "  AND MCNAME NOT LIKE 'HT%' "
            mySelect = mySelect & " AND (JSFACTOR.EVENTST BETWEEN ('" & strtShift & "') AND ('" & endShift & "')) "
            mySelect = mySelect & " ORDER BY SUBSTR (LINENAME,1,1), LENGTH (LINENAME), LINENAME, JSFACTOR.EVENTST  "

            myDataAdapter = New OracleDataAdapter(mySelect, conn)

            Dim Ds As New DataSet()
            myDataAdapter.Fill(Ds)

            Dim grpTot As DataTable = Ds.Tables(0).Clone

            'Make the changes to the Table structure.

            grpTot.Columns("EVENTTM").DataType = GetType(TimeSpan)
            grpTot.Columns("EVENTTM").ColumnName = "DURATION"

            grpTot.Columns.Add("TotalSum", GetType(TimeSpan))
            grpTot.Columns.Add("Count", GetType(Int32))

            Dim group2 As IEnumerable(Of DataRow) = _
From row In Ds.Tables(0).AsEnumerable() _
           Group row By LINENAME = row.Field(Of String)("LINENAME"), _
           MCNAME = row.Field(Of String)("MCNAME") Into grp = Group _
        Select DTRow(grpTot, _
           New Object() {LINENAME, MCNAME, _
                         New TimeSpan(CType( _
                            grp.Average(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks),  _
                            Int64 _
                            ) _
                            ), _
              New TimeSpan( _
                                            grp.Sum(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks _ ...

Thank you for the code TnTinMN..
I'm working on it right now and hope it will give the desired ouput :)

Happy holiday to you too TnTinMN!
I'm not celebrate anything at the of December but will start busy with my wedding preparation. Another 4 months to go.. hehe (^_^)

Have a safe journey!

I dont know why my datatable image not appear at above post. here is the image:
table3

I have datatable looks like below:
table2

I want to create a stack chart that will produce something like this:
stack2

I don't know where to start. I have google about how to create stack column but still can't get it.

So far I have a chart but mcname not include (only have LINENAME at X-Axis, DURATION at Y-Axis and Count (As Frequency) at Secondary Y-Axis)

chart12

This is my chart code:

' Setup the chart
            With Chart1
                .DataSource = grpTot ''Datatable name
                .Legends.Clear()
                .ChartAreas.Clear()
                .BackColor = Drawing.Color.Linen

                .ChartAreas.Add(New ChartArea("Fred"))

                With .ChartAreas("Fred")
                    .AxisY.LabelStyle.Format = "HH:mm:ss"
                    .AxisY.Minimum = DateTime.FromOADate( _
                    Math.Floor(CDate(grpTot.Compute("min([ChartTime])", "True")).ToOADate)) _
                   .ToOADate

                    'Play with this to get the effect you want
                    .AxisX.LabelStyle.Interval = 1
                    .AxisX.LabelStyle.Format = "G"
                    .AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Auto
                    .AxisX.Title = "LINE"
                    .AxisY.Title = "AVERAGE LOST TIME (hh:mm:ss)"
                    .AxisY2.Title = "FREQUENCY"
                    .AxisX.TitleFont = New Drawing.Font("arial", 12)
                    .AxisY.TitleFont = New Drawing.Font("arial", 12)
                    .AxisY2.TitleFont = New Drawing.Font("arial", 12)
                    .AxisX.MajorGrid.Enabled = False
                    .AxisY.MajorGrid.Enabled = False

                End With

                .Series.Clear()
                .Series.Add(New Series("AVERAGE LOST TIME"))

                With .Series("AVERAGE LOST TIME")
                    .ChartArea = "Fred"
                    .ChartType = SeriesChartType.Column
                    .XValueType = ChartValueType.String
                    .XValueMember = "Linename"
                    .YValueType = ChartValueType.DateTime
                    .YValueMembers = "ChartTime"
                    .Color = Drawing.Color.DeepSkyBlue

                End With

                .Series.Add(New Series("FREQUENCY"))

                With .Series("FREQUENCY")
                    .ChartArea = "Fred"
                    .ChartType = SeriesChartType.Line
                    .BorderWidth = 2
                    .BorderColor = Drawing.Color.DarkOrange
                    .XValueType = ChartValueType.String
                    .XValueMember = "Linename"
                    .YValueType = ChartValueType.Int64
                    .YValueMembers = "Count"
                    .Color = Drawing.Color.DarkMagenta
                    .YAxisType = System.Web.UI.DataVisualization.Charting.AxisType.Secondary

                End With

            End With

Can someone help me please..

TnTinMn,
it works!
thanks again!

And again, i learned many new things in programming world,
thanks a lot to you!

May God bless you :)

TnTinMn, is it 'DataTime' or 'DateTime'? Because when i wrote datatime it has error:
Name 'DataTime' is not declared

Then I changed to 'DateTime' and got another error:
ToAODate' is not a member of 'Date'

Then I changed ToAODate to FromOADate and get this error:
Argument not specified for parameter 'd' of 'Public Shared Function FromOADate(d As Double) As Date'.

How to fix it?

Anyway this is the code:

   Private Sub Chart1_Customize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Chart1.Customize

        For Each dp As DataPoint In Chart1.Series("AVERAGE LOST TIME").Points

            If dp.YValues(0) > DateTime.FromOADate(Chart1.ChartAreas("Fred").AxisY.Minimum).Add(New TimeSpan(0, 3, 0)).FromOADate Then

                dp.Color = Color.Crimson
            End If
        Next

    End Sub

Thank you TnTinMN. Now it's working fine.

One more question, is the Chart control only accept Single datatype to do any event like above? (Example to Draw linear line)

Because currently I have to change the bar chart color, from blue to red, if the bar exceed the limit (00:03:00)

Before this I use below code to do it with other application that consist of single datatype data and it's working fine.
But when I want to do it with this application, I got stuck on how to convert 00:03:00 to single datatype.
Here is the code:

  For Each dp As DataPoint In Chart1.Series("Wilma").Points
            If dp.YValues(0) > 25 Then
                dp.Color = Color.Crimson
            End If
        Next

I try change 25 to "00:03:00" but of course it throw error like below (Conversion from 'string' to 'double' is not valid):
error18

How can I fix this?

TnTinMn, thank you for your support.

But I got line like below:
gr1

The line is at 00:05:00 something, not 00:03:00.
Is it because we use the linear calculation so that the line is not fixed to 00:03:00?
Is there has any other way I can draw a fixed line at 00:03:00?

Sorry TnTinMn if I always bothering you :(

Hi,
How can i draw a horizontal line in my chart?
Currently my chart look like below:
chart11

Before this i use below code to draw it but when i try to draw with this application (Y axis in datetime), it give me error like 'make sure not dividing by zero'

    Private Sub Chart1_PostPaint(ByVal sender As Object, ByVal e As ChartPaintEventArgs) Handles Chart1.PostPaint

        If TypeOf e.ChartElement Is ChartArea Then

            Dim area As ChartArea = CType(e.ChartElement, ChartArea)

            Dim x1 As Single = CSng(area.AxisX.ValueToPixelPosition(area.AxisX.Minimum))
            Dim x2 As Single = CSng(area.AxisX.ValueToPixelPosition(area.AxisX.Maximum))
            Dim y As Single = CSng(area.AxisY.ValueToPixelPosition(20))

            e.ChartGraphics.Graphics.DrawLine(New Pen(Color.Blue, width:=5), x1, y, x2, y)

        End If

    End Sub

Actually, I dont know what to put in the axisY.valuetopixelposition() because when i try to put something like 00:03:00 it give me syntax error.

I also tried to create another series with "00:03:00" value in the y axis and got the below result:
chart2

But as we can see, the line only start at 1st point of X-axis value, not from the Y-axis line.
Can someone help me please..

Forgot to tell you, this application is the continuation from here:http://www.daniweb.com/software-development/vbnet/threads/434993/chart-from-dataset

thank you TnTinMn.. i tried both suggestion and only the first one give me the desired result.

TnTinMn,
I have questions to ask you.

First, My application that use LINQ has to auto refresh every 30 minutes. I'm using this code in client side code.

<meta http-equiv="refresh" content="1800">

But the problem is, sometimes it works fine but sometimes it give me run-time error.
I'm using the same refresh code to the other page that not use LINQ and it works without giving any error.
Is this because the LINQ make my application slow until it throws the runtime error?

Second, I want to draw a horizontal line in my chart. Before this i use below code to draw it but when i try to draw with this application (y axis in timespan), it give me error like 'make sure not dividing by zero'

  Private Sub Chart1_PostPaint(ByVal sender As Object, ByVal e As ChartPaintEventArgs) Handles Chart1.PostPaint

        If TypeOf e.ChartElement Is ChartArea Then

            Dim area As ChartArea = CType(e.ChartElement, ChartArea)

            Dim x1 As Single = CSng(area.AxisX.ValueToPixelPosition(area.AxisX.Minimum))
            Dim x2 As Single = CSng(area.AxisX.ValueToPixelPosition(area.AxisX.Maximum))
            Dim y As Single = CSng(area.AxisY.ValueToPixelPosition(0.3))

            e.ChartGraphics.Graphics.DrawLine(New Pen(Color.Blue, width:=5), x1, y, x2, y)

        End If

Actually, I dont know what to put in the axisy.valuetopixelposition() because when i try to put something like 00:03:00 it give me syntax error.

I have a LINQ function to get 3 things :: Line, Average of Duration and Count
I have a problem to sort it based on Average Of Duration column.

Here is my code:

Dim group2 As IEnumerable(Of DataRow) = _
                From row In Ds.Tables(0).AsEnumerable() _
                    Group row By LINENAME = row.Field(Of String)("LINENAME") Into grp = Group _
            Order By (LINENAME >= Convert.ToString(LINENAME)) _
            Select DTRow(grpTot, _
               New Object() {LINENAME, _
                             New TimeSpan(CType( _
                                grp.Average(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks),  _
                                Int64 _
                                ) _
                                ), _
                                grp.Count() _
                                } _
                                )

How can I sort my LINQ based on the Average, not based on LINENAME like the above code?

I already solved this problem after few testing since last night. Yeay! (^__^)

Anyway, here is the code:

'''''' Start Join 2 Datatable ''''''

            Dim JoinResult = _
            From o In grpDT.AsEnumerable _
            Join a In grpTot.AsEnumerable _
            On a.Field(Of String)("Tantou") Equals o.Field(Of String)("Tantou") _
          Select New With _
          { _
            Key .operatorID = a.Field(Of String)("Tantou"), _
            Key .totalCount = o.Field(Of Int32)("Count"), _
            Key .TotalSum = a.Field(Of TimeSpan)("Duration"), _
            Key .Average = o.Field(Of TimeSpan)("Duration") _
          }

            DataGridView1.DataSource = JoinResult

Yes you are right.

However, I cannot do it straight from DB because the column Total Lost Time and Average are in Char datatype and I have to convert to timespan to do the summation and get the average for each Operator ID.

In this case, I use LINQ to generate both table.

But the problem is, I dont know how to combine both LINQ statement. That's why I have 2 datatable.

I have two datatables that generate a datagridview like below:

1) datatable name : grpDT 119
2) datatable name : grpTot 211

I want to merge both datatable so that I the datagridview will be like this:

34

what is the best way to do this?
do i need to create new datatable and merge it?

Hi, I have 2 datagridview.
1 to show TANTOU, TOTAL SUM of DURATION and COUNT of event happened.
Another 1 is to show TANTOU, AVERAGE of DURATION and COUNT of event happened.

I have use LINQ function to get the result.
But how can i combine it so that i can show both result in the same datagrid?
(means, I just use 1 LINQ function that can display TANTOU, SUM, AVERAGE, and COUNT)

here is the code of sum:

Dim group As IEnumerable(Of DataRow) = _
                From row In Ds.Tables(0).AsEnumerable() _
                    Group row By TANTOU = row.Field(Of String)("TANTOU") Into grp = Group _
                    Order By (TANTOU >= Convert.ToString(TANTOU)) _
            Select DTRow(grpDT, _
                                 New Object() {TANTOU, _
                                               New TimeSpan( _
                                                grp.Sum(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks _
                                                            ) _
                                                          ), _
            grp.Count() _
                                                         } _
                                                        )

And here is the code of average:

           Dim group As IEnumerable(Of DataRow) = _
                From row In Ds.Tables(0).AsEnumerable() _
                    Group row By TANTOU = row.Field(Of String)("TANTOU") Into grp = Group _
                    Order By (TANTOU >= Convert.ToString(TANTOU)) _
            Select DTRow(grpDT, _
               New Object() {TANTOU, _
                             New TimeSpan(CType( _
                                grp.Average(Function(r2 As DataRow) TimeSpan.Parse(r2.Field(Of String)("EVENTTM")).Ticks),  _
                                Int64 _
                                ) _
                                ), _
                                grp.Count() _
                                } _
                                )

OK I got it solved by this code:

 If ds.Tables(0).Rows.Count <> 0 Then
            line = Nothing

            For i As Integer = 0 To dt.Rows.Count - 1
                line = line & "   " & dt.Rows(i)("LINE").ToString()

            Next

            lblLine.Text = line

        End If

I want to display datatable result in a label.
I have something like this :
PLEASE TAKE ACTION FOR LINE LABEL

But i want the result to be like this:
PLEASE TAKE ACTION FOR LINE Z3, Z5, Z8

I try to use loop but still cant get the result that I want. Here is my loop:

        If ds.Tables(0).Rows.Count <> 0 Then

            For i As Integer = 0 To dt.Rows.Count - 1
                line += dt.Rows(i)("LINE").ToString()
                lblLine.Text = line

            Next

        End If

Can someone help me please..

Thank you all.. The problem has been solved :)

Dim SQLstr As String = " SELECT VAC_JSINFO.LINE, VAC_LineStatus.Status " & vbCrLf & _
                       " FROM VAC_LineStatus INNER JOIN " & vbCrLf & _
                       " VAC_JSINFO ON VAC_LineStatus.Line = VAC_JSINFO.LINE " & vbCrLf & _
                       " WHERE (VAC_JSINFO.COLLECTDATE > '" & strtTime & "')  AND (VAC_JSINFO.COLLECTDATE < '" & endTime & "')  AND (VAC_JSINFO.KYUERR1 >= 0)  " & vbCrLf & _
                       " AND (VAC_LineStatus.Status = 1) " & vbCrLf & _
                       " GROUP BY VAC_JSINFO.LINE, VAC_LineStatus.Line, dbo.VAC_LineStatus.Status  " & vbCrLf & _
                       " HAVING (SUM((VAC_JSINFO.KYUERR1 + VAC_JSINFO.VISION1 + VAC_JSINFO.KEIJYOU1) * VAC_JSINFO.UNITCOST) > '25') "

I want to perform an UPDATE query but i'm getting this error: errorHAVING

This is my Sub in vb.net:

   Public Sub changeStatus()

        Dim Sqlstr As String
        Dim connectionString As String = "server=xxxx;uid=xxxx;pwd=xxxx;database=xxxx"
        Dim strtTime As String
        Dim endTime As String

        strtTime = DateTime.Today.ToString("yyyy/MM/dd") & " " & "06:15:00"
        endTime = DateTime.Today.ToString("yyyy/MM/dd") & " " & "18:15:00"

        Sqlstr = "   UPDATE    dbo.VAC_LineStatus  "
        Sqlstr = "   SET   SET Status = @Status   "
        Sqlstr = "   WHERE     (Line IN  "
        Sqlstr = "  (SELECT     VAC_JSINFO.LINE  "
        Sqlstr = "   FROM    dbo.VAC_LineStatus INNER JOIN  "
        Sqlstr = "    VAC_JSINFO ON dbo.VAC_LineStatus.Line = VAC_JSINFO.LINE  "
        Sqlstr = "    WHERE      (VAC_JSINFO.COLLECTDATE > '" & strtTime & "')  AND (VAC_JSINFO.COLLECTDATE < '" & endTime & "')  AND   "
        Sqlstr = "   (VAC_JSINFO.KYUERR1 >= 0)  "
        Sqlstr = "    GROUP BY VAC_JSINFO.LINE, VAC_LineStatus.Line    HAVING(SUM((VAC_JSINFO.KYUERR1 + VAC_JSINFO.VISION1 + VAC_JSINFO.KEIJYOU1) * VAC_JSINFO.UNITCOST) > '25')))"
        Sqlstr = "  HAVING  (SUM((VAC_JSINFO.KYUERR1 + VAC_JSINFO.VISION1 + VAC_JSINFO.KEIJYOU1) * VAC_JSINFO.UNITCOST) > '25')))  "

        Using connection As New SqlConnection(connectionString)
            Dim cmdInsert As New SqlCommand(Sqlstr, connection)

            cmdInsert.Parameters.Add("@Status", Data.SqlDbType.NVarChar).Value = 1

            connection.Open()
            cmdInsert.ExecuteNonQuery()
        End Using

    End Sub

When i execute the query in SQL Server, it's working fine but why it get error when trying to execute using vb.net?

Can someone help me please...

Hi, this is a webpage.

however, i changed my process flow and you can refer to http://www.daniweb.com/software-development/vbnet/threads/439651/how-to-change-bar-chart-color-based-on-value-in-database

And in my code, i already set the timer to refresh every certain minutes.

no it still not work.. i try to reload it and nothing happen. it still wont change to green.

Here is my complete code:

    Option Explicit On
    Imports System.Data.SqlClient
    Imports System.Data
    Imports System.Web.UI.DataVisualization.Charting
    Imports System.Drawing

    Partial Class LineSpoilage
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Dim DBConn As New SqlConnection("server=xxxx;uid=xxxx;pwd=xxxx;database=xxxx")
            Dim DBCmd As New SqlCommand
            Dim da As New SqlDataAdapter
            Dim ds As New DataSet()
            Dim strtTime As String
            Dim endTime As String

            strtTime = DateTime.Today.ToString("yyyy/MM/dd") & " " & "06:15:00"
            endTime = DateTime.Today.ToString("yyyy/MM/dd") & " " & "18:15:00"

            Try
                DBConn.Open()

                Dim SQLstr As String = " SELECT   LINE, SUM(KYUERR1 + VISION1 + KEIJYOU1) AS PICKUP_ERR, SUM((KYUERR1 + VISION1 + KEIJYOU1) * UNITCOST) AS RM "
                SQLstr &= " FROM         VAC_JSINFO "
                SQLstr &= " WHERE       (COLLECTDATE > '" & strtTime & "') AND (COLLECTDATE < '" & endTime & "') AND (KYUERR1 >= 0) "
                SQLstr &= " GROUP BY LINE "
                SQLstr &= " ORDER BY RM DESC "

                Dim myCommand As New SqlCommand(SQLstr, DBConn)
                da.SelectCommand = myCommand
                da.Fill(ds)

                DataGridView1.DataSource = ds
                DataGridView1.DataBind()

                '''''''''CREATE GRAPH ''''''''''''''

                With Chart1
                    .DataSource = ds
                    .Legends.Clear()
                    .ChartAreas.Clear()
                    .ChartAreas.Add(New ChartArea("Fred"))

                    With .ChartAreas("Fred")

                        'Play with this to get the effect you want
                        .AxisX.LabelStyle.Interval = 1
                        .AxisY.LabelStyle.Interval = 5
                        .AxisX.Title = "LINE"
                        .AxisY.Title = "SPOILAGE (RM)"
                        .AxisX.TitleFont = New Font("arial", 12)
                        .AxisY.TitleFont = New Font("arial", 12)
                        .AxisX.MajorGrid.Enabled = False

                        Dim maxY = GetMax()

                        If maxY < 30 Then
                            .AxisY.maximum = 30

                        End If
                    End With

                    .Series.Clear()
                    .Series.Add(New Series("Wilma")) ...

How can I change the color of bar chart based on value in database column?

For example, in table "STATUS" in my database, I have 3 type of value. What I want is:

1) If the value = 0, then color will change to blue.

2) If the value = 1, then color will change to red.

3) If the value = 2, then color will change to green.

I use MSChart to create the chart.

I set the default color as blue.
I tried to store STATUS value in dataset and do for loop to retrieve the value.
If i found value = 2, then it will change to green.
Else the color will be red.
But its not worked.

Here is the code:

       For Each dp As DataPoint In Chart1.Series("Wilma").Points
            For i As Integer = 0 To grpDT.Rows.Count - 1
                    If (grpDT.Rows(i).Item("Status").ToString() = "2") Then
                        dp.Color = Color.Green
                    Else
                        dp.Color = Color.Red
                    End If
                Next
        Next

Can someone help me please. I'm stuck at this almost a week :(

Hi,
How can i change the bar chart color after I click a button?

Here is the senario. I have a bar chart to show line progress. Here is the 3 condition for the bar chart:
1) Before the bar chart reach maximum limit, the color will set to blue.
2) When the bar chart reach maximum limit, the color will set to red.
3) When someone fill in countermeasure form in another page and click button submit, the bar chart will change to green.

For the first one, i just set the color in the server-side code :

.Color = Color.DodgerBlue

For the second one, i use Chart1_Customize to change the color when reach maximum limit. For example i set maximum limit to 25.

Private Sub Chart1_Customize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Chart1.Customize
        For Each dp As DataPoint In Chart1.Series("Wilma").Points
            If dp.YValues(0) > 25 Then
                dp.Color = Color.Crimson
            End If
        Next
    End Sub

Now for the third one, how can I change the color to green after the user click a submit button on the second page?

Alright.. I got what I want.. hehe.. Thank you very much :)

Anyway, here is the code in second page:

<div>

        Please Insert Countermeasure for Line&nbsp;
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    </div>

And this is the code behind in the second page:

Label1.Text = Request.QueryString("LINE")

Thank you very much! (^_^)

I did some changes in datagridview properties like below:

 <Columns>
 <asp:HyperLinkColumn DataNavigateUrlField="LINE" DataTextField="LINE" 
                    HeaderText="LINE" DataNavigateUrlFormatString="Dust.aspx?Line={0}" Target="_blank">
                </asp:HyperLinkColumn>

and the result, i got it works like below:
hyperlinkOk

Now, how can I get what LINE did i choose, for example i click at M23 to appear in the second page?

This is the example output that I want, place somewhere in the second page:

CNTRM

where the M23 got from 1st page that user click.

Thank you :)

Hi Reverend Jim! Thank you for your reply.

Actually, I dont know where to start first since I'm still new in programming world and this is the first time i'm trying to manipulate gridview.

May I know where can I add the cellClick event handler in the code that i provided above?

hi,

I have a Gridview like below:
Gv3

What I want is:
1) User can click at LINE column, for example user click at M23 and it will redirect to other page.
2) At the other page, it will display something like this:
Please insert countermeasure for M23

where M23 is get from what user click.

How can I do that?

Here is my code:

Dim DBConn As New SqlConnection("server=xxxx;uid=xxxx;pwd=xxxx;database=xxxx")
            Dim DBCmd As New SqlCommand
            Dim da As New SqlDataAdapter
            Dim ds As New DataSet()
            Dim strtTime As String
            Dim endTime As String

            strtTime = DateTime.Today.ToString("yyyy/MM/dd") & " " & "06:15:00"
            endTime = DateTime.Today.ToString("yyyy/MM/dd") & " " & "18:15:00"

            Try
                DBConn.Open()

                Dim SQLstr As String = " SELECT   LINE, SUM(KYUERR1 + VISION1 + KEIJYOU1) AS PICKUP_ERR, SUM((KYUERR1 + VISION1 + KEIJYOU1) * UNITCOST) AS RM "
                SQLstr &= " FROM         VAC_JSINFO "
                SQLstr &= " WHERE       (COLLECTDATE > '" & strtTime & "') AND (COLLECTDATE < '" & endTime & "') AND (KYUERR1 >= 0) "
                SQLstr &= " GROUP BY LINE "
                SQLstr &= " ORDER BY RM DESC "

                Dim myCommand As New SqlCommand(SQLstr, DBConn)
                da.SelectCommand = myCommand
                da.Fill(ds)

                GridView1.DataSource = ds
                GridView1.DataBind()

I got this problem solved.
Here is the solution:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        'create the mail message
        Dim mail As New MailMessage()

        'set the addresses
        mail.From = New MailAddress("xxxx@xxx.com")
        mail.[To].Add("xxxx@xxxx.xxxx.com")

        'set the content
        mail.Subject = "Important! Spoilage Exceed!"
        mail.Body = "Please take further action!"

        'set the server
        Dim smtp As New SmtpClient("xxxxx")
        smtp.Port = 25

        smtp.Send(mail)
        Response.Write("Your Email has been sent sucessfully - Thank You")

    End Sub

Hi,

Is it possible to send an email from SMTP server, for example from do_not_reply@xxxx.xxx.com, without have the server credential (username and password) inside my code?

I tried one code, it works, but it send from my email account. Not from SMTP server.

I also tested several code but I cant proceed to send the email since it need server credential.
And my Symantec popup error like

Symantec email policy:
Your email message was unable to be sent because your mail server rejected the message.
550 5.7.1 Client does not have permissions to send as this sender

can someone help me pls..?