Guy Moyal

Guy Moyal

  • NA
  • 24
  • 0

Beginner help with DB counting

Jul 3 2007 9:31 AM
Hello all!

I'm new to the C# language so please bare with me :)

I've created a web app that connects to a database and randomly selects rows that then goes into a .js file by streamwriter.
The .js file is used for displaying a script with data from the db.
Currently, it writes out what I need but at a limit of 7 due to a variable written in javascript by the streamwriter. I would like it to have no limitation so that it would write as many javascript variables as the count of the rows are.
How is this possible?

This is sort of what I have done so far:

        SqlConnection con = new SqlConnection("Server=a;uid=a;database=tp");
        SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM TPCPTbl ORDER BY NEWID()", con);
SqlCommandBuilder MyCB = new SqlCommandBuilder(da);
        DataSet ds = new DataSet("TPCPTbl");
        da.Fill(ds,"TPCPTbl");
        StreamWriter sw = new StreamWriter(@"C:\\work/cp/main.js");
        sw.Write(

"var c1 = ...."
//here is where I would like to have it count and give names such as c2, c3, etc depending on the number of rows

);

Last question:

How do i break lines in streamwriter?
I've been doing this: "var c1 = ..." +
                                   "var c2 = ..."
);

The problem with this is that it doesn't break the line inside the .js file.

Thank you,

Guy

Answers (21)