locked
Datareader to databuilder RRS feed

  • Question

  • User1611044070 posted

    I was trying to export only specific values from the gridview to word doc.


     protected void Button4_Click(object sender, EventArgs e)
            {

     protected void Button4_Click(object sender, EventArgs e)

            {

     string Wordpath = @"C:\Test\Test.doc";


                sconn.Open();

                 SqlCommand cmd = new SqlCommand("select Name,Email from Register where PhoneNo='1234'", sconn);

                SqlDataReader rdr = cmd.ExecuteReader();

    StringBuilder WriteText = new StringBuilder();

                while (rdr.Read())

    {

    WriteText.Append(rdr["Name"].ToString()).Append(rdr["Email"].ToString());

                }

    FileStream fs = File.Create(Wordpath);

                fs.Close();

                StreamWriter sw = new StreamWriter(Wordpath);

    sw.write(WriteText );

    sw.close();

    }

    Here Im getting only the last value Email in the word doc..


    I need to get both Name and Email in 2 rows like

    for eg;Name is "bee" Email is "1233@gmail.com"


    So my output will be 

    bee

    1233@gmail.com


    how to achieve this?

    Wednesday, December 23, 2009 10:11 AM

All replies

  • User622904130 posted

    why not use

    string.format({0}@{1},rdr["Name"].ToString(),rdr["Email"].ToString())

     

    Wednesday, December 23, 2009 12:33 PM