This is probably the problem:
foreach(DataRow row in dt.rowsList)
rowsList is not a property of a DataTable. It should be:
foreach(DataRow row in dt.Rows)
On Thursday, February 21, 2013 5:30:22 PM UTC-5, Matevz Uros Pavlic wrote:
>
> Hi,
>
> i figured the Item error out. Seem like in c# you can write it directly
> like :
>
> @using System.Data;
> @using System.Collections.Generic;
> @using System.Data.SqlClient;
> @{
>
> Layout = null;
>
>
> string connectionString="Server=192.168.1.125,1433\\sqlexpress;
> Database=HEK; Uid=sa; Pwd=lubelincek12121";
>
> DataTable dt = new DataTable();
>
> using (SqlConnection conn = new SqlConnection(connectionString))
> {
> conn.Open();
> using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT Datum,
> Sava, RPWS1 FROM vws", conn))
> {
> adapter.Fill(dt);
>
>
>
> List<string> rowsList = new List<string>();
>
> rowsList.Add("['Datum', 'Sava', 'RPWS1']");
>
>
> foreach(DataRow row in dt.rowsList)
>
> {
> rowsList.Add("[" + row["Datum"] + ", " + row["Sava"] +
> ", " + row["RPWS1"] + "]");
> }
> String rows = String.Join(", ", rowsList);
>
>
>
> //Object o = dt.Rows[0]["RPWS1"];
> //Response.Write(o);
>
>
> };
>
>
>
> };
>
>
>
> }
>
>
> But the error about rowsList remains. I can't figure out what's wrong....
>
> Thanks, m
>
>
> On Thursday, 21 February 2013 16:30:05 UTC+1, asgallant wrote:
>>
>> rowsList is a list of strings which will be printed in the javascript,
>> translating the C# DataTable into a Google Visualization DataTable.
>>
>> On Thursday, February 21, 2013 5:12:01 AM UTC-5, Matevz Uros Pavlic wrote:
>>>
>>> No luck...
>>>
>>> If I test it like this :
>>> Object o = dt.Rows[0]["RPWS1"];
>>>
>>> The values are correct.
>>>
>>> What is rowsList in the code you posted?
>>>
>>> Thanks, m
>>>
>>>
>>>
>>> On Thursday, 21 February 2013 00:29:17 UTC+1, asgallant wrote:
>>>>
>>>> This loop here is accessing the contents of the row:
>>>>
>>>> foreach(DataRow row in dt.rows) {
>>>> rowsList.Add("[" + row.item["Datum"] + ", " + row.item["Sava"] + ",
>>>> " + row.item["RPWS1"] + ", " + row.item["RPWS2"] + ", " +
>>>> row.item["RPWS3"]
>>>> + "]");
>>>> }
>>>>
>>>> On Wednesday, February 20, 2013 5:12:13 PM UTC-5, Matevz Uros Pavlic
>>>> wrote:
>>>>>
>>>>> Hi,
>>>>> ok, but how can i check this? if i do :
>>>>>
>>>>> var a = dt.Rows;
>>>>> Response.Write(a);
>>>>>
>>>>> I get :
>>>>> System.Data.DataRowCollection
>>>>>
>>>>> How could i check what exaclty is stored in DataTable dt?
>>>>>
>>>>>
>>>>> On Wednesday, 20 February 2013 15:55:33 UTC+1, asgallant wrote:
>>>>>>
>>>>>> If it is properly filled, the dt.Rows property should contain an
>>>>>> array of rows.
>>>>>>
>>>>>> On Wednesday, February 20, 2013 3:51:04 AM UTC-5, Matevz Uros Pavlic
>>>>>> wrote:
>>>>>>>
>>>>>>> hi,
>>>>>>>
>>>>>>> ok, i'll try and find how this goes. Another thing, do you have any
>>>>>>> idea how to check if DataTable is filled correcty from SQL query?
>>>>>>>
>>>>>>> Thanks, m
>>>>>>>
>>>>>>> 2013/2/20 asgallant <[email protected]>
>>>>>>>
>>>>>>>> You have to parse the contents of the data structure returned by
>>>>>>>> your query and output the data into a format the Visualization API can
>>>>>>>> understand. If you have the C# DataTable populated correctly, then
>>>>>>>> you
>>>>>>>> should be able to use something like this to output it in the correct
>>>>>>>> format:
>>>>>>>>
>>>>>>>> @{
>>>>>>>> // query database and populate DataTable dt first
>>>>>>>>
>>>>>>>> // create an array of rows
>>>>>>>> List<string> rows = new List<string>();
>>>>>>>> rowsList.Add("['nivo Sava', 'RPWS1', 'RPWS2', 'RPWS3']");
>>>>>>>> foreach(DataRow row in dt.rows) {
>>>>>>>>
>>>>>>>> rowsList.Add("[" + row.item["Datum"] + ", " +
>>>>>>>> row.item["Sava"] + ", " + row.item["RPWS1"] + ", " + row.item["RPWS2"]
>>>>>>>> + ",
>>>>>>>> " + row.item["RPWS3"] + "]");
>>>>>>>> }
>>>>>>>> String rows = String.Join(", ", rowsList);
>>>>>>>> }
>>>>>>>> <script type='text/javascript'
>>>>>>>> src="http://www.google.com/**jsapi<http://www.google.com/jsapi>
>>>>>>>> "></script>
>>>>>>>>
>>>>>>>> <script type="text/javascript>
>>>>>>>> function drawChart () {
>>>>>>>> var data = google.visualization.**
>>>>>>>> arrayToDataTable([@rowsList]);
>>>>>>>> var chart = new google.visualization.**LineChart(document.**
>>>>>>>> getElementById('chart_div');
>>>>>>>> chart.draw(data, {
>>>>>>>> height: 350,
>>>>>>>> width: 900,
>>>>>>>> title: 'Absolutna kota vode v tesnilni zavesi',
>>>>>>>> vAxis: {
>>>>>>>> maxValue: 165.5,
>>>>>>>> minValue: 159,
>>>>>>>> title: 'absolutna kota'
>>>>>>>> }
>>>>>>>> });
>>>>>>>> }
>>>>>>>>
>>>>>>>> google.load('visualization', '1', {packages: ['corechart']});
>>>>>>>> google.setOnLoadCallback(**drawChart);
>>>>>>>> </script>
>>>>>>>>
>>>>>>>> On Tuesday, February 19, 2013 6:05:06 PM UTC-5, Matevz Uros Pavlic
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Hi again,
>>>>>>>>>
>>>>>>>>> these were missing :
>>>>>>>>>
>>>>>>>>> @using System.Data;
>>>>>>>>>
>>>>>>>>> @using System.Collections.Generic;
>>>>>>>>> @using System.Data.SqlClient;
>>>>>>>>>
>>>>>>>>> But it still doesn't work.
>>>>>>>>>
>>>>>>>>> I (think) I managed to copy SQL table to DataTable of c# by :
>>>>>>>>>
>>>>>>>>> @using System.Data;
>>>>>>>>>
>>>>>>>>> @using System.Collections.Generic;
>>>>>>>>> @using System.Data.SqlClient;
>>>>>>>>> @{
>>>>>>>>>
>>>>>>>>> Layout = null;
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> string connectionString="Server=xxx.**xxx.xxx.xxx; Database=HEK;
>>>>>>>>> Uid=sa; Pwd=xxxxx";
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> DataTable dt = new DataTable();
>>>>>>>>>
>>>>>>>>> using (SqlConnection conn = new SqlConnection(**connectionString))
>>>>>>>>> {
>>>>>>>>> conn.Open();
>>>>>>>>> using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT
>>>>>>>>> Sava, rpws1 FROM VWS WHERE ID > 2200", conn))
>>>>>>>>>
>>>>>>>>> {
>>>>>>>>> adapter.Fill(dt);
>>>>>>>>> };
>>>>>>>>> };
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Now i'd have to pass it to Google charts, to draw the plot... ?
>>>>>>>>>
>>>>>>>>> Of course this doesn't work :
>>>>>>>>> var data = google.visualization.**arrayToDataTable(@dt);
>>>>>>>>>
>>>>>>>>> Do you have any ideas on this...i am reaaaally lost here...
>>>>>>>>>
>>>>>>>>> Tnx
>>>>>>>>>
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>> Groups "Google Visualization API" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>> send an email to
>>>>>>>> [email protected].
>>>>>>>> To post to this group, send email to
>>>>>>>> [email protected].
>>>>>>>> Visit this group at
>>>>>>>> http://groups.google.com/group/google-visualization-api?hl=en.
>>>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.