Hi, looking for help and need pointing in the right direction, can anyone assist?

Have a data file (txt) that contains 10000 numbers/data points. Storing the data file as varbinary(MAX) in an SQL table.

My goal is to retrieve the file on user request and plot/chart the numbers as a line chart.

No problem in getting DataReader to display the numbers directly to the screen, but I'm stuck as to how get the numbers into a DataSet (or table) to plot a chart....

Can anyone offer advice or give direction?

Many thanks. Miry

If you are able to get numbers from the file into data reader, then you can also convert the data reader into data table.

Refer this code

SqlConnection cn = new SqlConnection("Server=(local);database=Northwind;user id=sa;password=;");
        string sql = "Select * from Employees";
        SqlCommand cmd = new SqlCommand(sql, cn);
        cn.Open();
        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        
        DataTable dt = new DataTable();
        dt.Load(dr); 
        dr.Close();

If you are able to get numbers from the file into data reader, then you can also convert the data reader into data table.

Refer this code

SqlConnection cn = new SqlConnection("Server=(local);database=Northwind;user id=sa;password=;");
        string sql = "Select * from Employees";
        SqlCommand cmd = new SqlCommand(sql, cn);
        cn.Open();
        SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        
        DataTable dt = new DataTable();
        dt.Load(dr); 
        dr.Close();

Thank you Ramesh, for your reply and example.

The problem is orientated around the txt varbinary(max) field. The sql table contains many rows and each row has a data field containing a txt file (the varbinary one). A stored procedure shuffles off and fetches the correct varbinary field from a specific record, without a problem and the DataReader will grab the contents of the varbinary field (10000 numbers in a line i.e. -2 -2 -2 -2 -2 -3 -3 -3 -3 -3 -4 -4 -4 -4 -4 -4 -4 -4 -5 -5 -5 -5 -5 -5 -5 -6 -6 -8 -7 -8 -7 -8 -7 -8 -7 -7 -7 -7 -8 -7 -8 -7 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -7 -6 -6 -6 -6 -6 -6 -5 -5 -5 -5 -5 -4 -a4 -4 -4 -4 -3 -4 -4 -4 -4 -4 -4 -5 -5 -5 -5 -6 -6 -6 -6 etc etc).

The DataReader will display them when i use Response.BinaryWrite, like above.

Tried -

DataTable dt = new DataTable();
dt.Load(DataReader);

But it the DataTable doesn't hold any data, as a guess because it is a single field.

How can i get the 100000 numbers into a record set without writing a file out and importing it?

Any help, suggestion is very welcome.

This article has been dead for over six months. Start a new discussion instead.