0

I am working on C# windows form application, it has five fields namely ID, NAME, CONTACTNUMBER, EMAIL AND DESCRIPTION (MultiLine) and in database it has respectively fields, while saving data for Description field i use newline(next line) like below:

    {XYZ,
    1st, STREET,
    CITYNAME.}

In database it will save in single line but when i try print using crystal report then also it will print in single line as such:

like{XYZ,1st,STREET,CITYNAME}

but I want output like this:

    {XYZ,
    1st, STREET,
    CITYNAME.} 

How to Achieve this?

The following is the code to save to the database:

    con.Open();
          SqlCommand cmd = con.CreateCommand();
          cmd.CommandType = CommandType.Text;
          cmd.CommandText = "insert into AddCaseSheet values('" +ID.Text + "',
    '" + NAME.Text + "','" + CONTACTNUMBER.Text + "','" + EMAIL.Text + "','"+DESCRIPTION.Text+"')";
    con.Close();

And the code To Print:

con.Open();
            SqlDataAdapter sda = new SqlDataAdapter("Select * from DETAILS where ID= '" + ID.Text + "'", con);
            DataSet dst = new DataSet();
            sda.Fill(dst, "DETAILS");
            crystalReport.Load(@"E:\TrialTest\CrystalReport2.rpt");
            crystalReport.SetDataSource(dst);
            crystalReportViewer1.ReportSource = crystalReport;
            con.Close();

What I want is while printing description column it should be in new line format, any reference to learn about it or any video or anything, will be good

Matt
  • 13,833
  • 2
  • 16
  • 28
Sahara
  • 23
  • 6
  • 1
    Why are you typing in CAPITALS? It's horrible to read. Please format your question. – DavidG Sep 23 '16 at 17:11
  • 1
    put "@" at beginning of string literals and check db can save necessary characters. – huseyin tugrul buyukisik Sep 23 '16 at 17:14
  • 1
    you should parameterize your insert statement to protect against sql injection. here is an article on how and why http://stackoverflow.com/questions/7505808/why-do-we-always-prefer-using-parameters-in-sql-statements – Matt Sep 23 '16 at 17:16
  • once you do parameterize your query you don't need to do anything the white space should get saved in the database. it should be getting saved there now so perhaps if you copy the value directly from the db to notepad do you see the new lines? – Matt Sep 23 '16 at 17:18
  • Also check to make sure the report is set to allow the field to grow to accommodate multi line. – Matt Sep 23 '16 at 17:27
  • 1
    As @huseyintugrulbuyukisik said you need to use `@` if you want a newline in the source code to show up in the string itself. As written your two lines `cmd.CommandText = "insert into AddCaseSheet values('" +ID.Text + "',` gives me a compile error: "Error CS1010 Newline in constant". If you want your manually entered newline to show up you need `@` on the string containing the enter which for you would be here after the plus sign: `cmd.CommandText = "insert into AddCaseSheet values('" +ID.Text + @"',` – Quantic Sep 23 '16 at 18:03
  • are you formatting the field in design or just writing code for everything? – Siva Sep 24 '16 at 14:01

1 Answers1

0

Select field which you want to make multiline right-click>Format field> select 'Common' tab in opened window then check "Can Grow" checkbox and save .

The field will become multiline.

Sahara
  • 23
  • 6