I am using a webchart and a sqldatasource command.
I have a question..
Is it possible for me to, in the code behind, to set the "select command" statement from the server side?
I want to do this so I can have something like..
Select * from table where value = textbox.value
THe user gets to the page and gets the initial chart data, then allow them to enter a value in a text box to refresh the chart but change the sql statement to include the value from the textbox they entered.
Thanks for the help.
That gave me the idea I needed.
I basically got a dataset, got the table name and assigned those to the graph control. Works great.
Hi, as far as I know, it is possible to "refresh" the chart at runtime, I do that by creating a SqlCommand Object, wich can be any SQL statement, and then fill a DataSet with the result of the query, but you have to be careful with the resulting data, here's a example using a StoredProcedure in the server that accepts a parameter:
-------------------------------------Starts Query------------------------------------
Dim com As New SqlCommand("Compare2Y")com.CommandType = CommandType.StoredProcedure
com.Parameters.Add("@Y1", SqlDbType.Int)com.Parameters("@Y1").Value = 2009
com.Connection = New SqlConnection(MainConnectionString)Dim dr As SqlDataReadercom.Connection.Open()dr = com.ExecuteReader()
----------------------------This part is for creating the DS------------------------------------
ds.Tables.Add("DATOS")ds.Tables("DATOS").Columns.Add("Fallecidos", Type.GetType("System.Int32"))ds.Tables("DATOS").Columns.Add("Lesionados", Type.GetType("System.Int32"))ds.Tables("DATOS").Columns.Add("Accidentes", Type.GetType("System.Int32"))ds.Tables("DATOS").Columns.Add("Personales", Type.GetType("System.Int32"))ds.Tables("DATOS").Columns.Add("Materiales", Type.GetType("System.Int32"))Dim fila As DataRowWhile dr.Read() fila = ds.Tables("DATOS").NewRow() fila("Fallecidos") = CInt(dr(1)) fila("Lesionados") = CInt(dr(2)) fila("Accidentes") = CInt(dr(3)) fila("Personales") = CInt(dr(4)) fila("Materiales") = CInt(dr(5)) ds.Tables("DATOS").Rows.Add(fila)
End While
-------------------------------------Ending Query------------------------------------
dr.Close()com.Connection.Close() com = Nothingdr = Nothing
-------------------------------------Adding the result into a chart------------------------------------
Chart1.DataSource = dsChart1.DataMember = "DATOS"Chart1.DataBind()
This code can be on a Subroutine that can be called anytime, passing the value asked for the StoredProcedure.
Bye!