DataColumn Expression

  • Thread starter Thread starter Joel Rumerman
  • Start date Start date
J

Joel Rumerman

Is there a way to insert a blank line (\n) into a DataColumn expression?

i.e. Dim dc as new DataColumn("test1", Type.GetType("System.String"),
"Address1 + '\n' + Address2"))

I can't seem to get .NET to recognize the escapt character

Thx, Joel
 
* "=?Utf-8?B?cmVzaG1hNQ==?= said:
I had the same problem. You can use Environment.NewLine as a workaround.

.... or 'ControlChars.NewLine' ;-).
 
Thx!

However, I must be missing something ...

dt.Columns.Add(New DataColumn("AddressExpr", Type.GetType("System.String"),
"Address1 + 'ControlChars.NewLine' + City + ', ' + State + ' ' +
PostalCode"))
just puts a 'ControlChars.NewLine' in the returned string.
(Environment.NewLine does the same thing.)

Any ideas??

Thx, Joel
 
Hi Joel,

Environment.NewLine is a constant in .Net Framework, you should not place
it in the "", or it will be treated as a string not a constant.

So do like this:
dt.Columns.Add(New DataColumn("AddressExpr", Type.GetType("System.String"),
"Address1 +"+Environment.NewLine + "Address2"))

====================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Jeffrey,

Thanks for your suggestion.

I applied your suggestion, but it did not work for me. My expression is
exactly what you have written below and viewing the quick watch of the
column expression shows
"Address1 +
Address2"

(In the quick watch window it has the square control characters to indicate
a carriage return line feed.) So, the expression has the blank line in it,
but when I bind it do a data grid, the blank line gets ignored.

The code is the following ...

Dim ds As CorporateReporting.EDService.AccountContactQueryResults =
mgrWidgets.SearchForAccountsOrContacts(1, Me.rButtonAccount.Checked,
Me.txtName.Text, Me.txtName.Text, Me.txtCity.Text, Me.txtState.Text,
Me.txtPostalCode.Text, (Trim(Me.txtAreaCode.Text) &
Trim(Me.txtExchange.Text) & Trim(Me.txtSuffix.Text)),
Me.cmboNameCriteria.SelectedValue, 500, "")
Dim dt As DataTable

If Me.rButtonAccount.Checked Then

dt = ds.Accounts.Copy()

Else

dt = ds.Contacts.Copy()

End If

dt.Columns.Add(New DataColumn("AddressExpr", Type.GetType("System.String"),
"Address1 +" + Environment.NewLine + " Address2"))

Me.DataGrid1.DataSource = dt

Any ideas?

Thanks, Joel
 
Hi Joel,

I will spend some time on this issue, I will reply to you ASAP.
Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Joel,

Sorry for letting you wait for so long time. We can use the following
syntax for DataColumn.Expression property:
ds.Tables[0].Columns.Add( "test", typeof( string ), "job_id +
'"+Environment.NewLine+"'+job_desc");

Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Joel,

Thanks very much for your feedback. I am glad it works for you :-)

If you need further help, please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top