Hi,
I have managed to display a point chart using the values from the columns in a MS SQL database using SqlDataReader, below is the code.
I want the chart to display the points for the latest 10 entries not the entire column, how can i do that?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mySelectQuery As String = "SELECT test_x, test_y FROM test_x_y;"
Dim myConnection As New SqlConnection("Data Source= ONC-ECC54; Initial Catalog=graph_test; Integrated Security=True")
Try
' Open the connection
myConnection.Open()
' Create a database command on the connection using query
Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
'Chart1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' Set series members names for the X and Y values
'Chart1.Series("Series1").XValueMember = "test_x"
'Chart1.Series("Series1").YValueMembers = "test_y"
' Create a database reader
Dim myReader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Chart1.Series("Series1").Points.DataBindXY(myReader, "test_x", myReader, "test_y")
myReader.Close()
myConnection.Close()
Catch Ex As Exception
Label1.Text = "Error in acquiring graph chart " & Ex.ToString
End Try
End Sub
Thanks a lot in advance.
Try this way.
SELECT TOP 10 column_name FROM table_name
ORDER BY column_name DESC;
Thanks a lot Ramesh, did the job.
沒有留言:
張貼留言