C# - What Is The Difference Between Xxx.tostring() And (string)xxx
Jan 24, 2011whats the difference in the two string methods below?
string str1 = dr["RAGStatusCID"].ToString();
string str2 = (string)dr["Description"];
whats the difference in the two string methods below?
string str1 = dr["RAGStatusCID"].ToString();
string str2 = (string)dr["Description"];
I want to Know What is the difference between .ToString and Convert.To string?
View 4 Replieson VWD 2005 this code works fine, but on 2008 it says I haven't created an instance of the object. I want to convert the object connString (a connection string) into a string.
'This acceses the virtual directory web.config file for connection strings
'We have to convert the object to a connection string
Dim rootWebConfig As System.Configuration.Configuration
rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/VirtualDirec")
Dim connString
As System.Configuration.ConnectionStringSettings
connString = rootWebConfig.ConnectionStrings.ConnectionStrings("ConnectString1")
Dim strConnString
As
String = connString.ToString().......
I ran into a bug that was bothering me. I had JObject that I thought would be fine with
obj["role"].ToString()
The string was there and everything. A final resort was to change to a
(string)obj["role"]
just to see what happens and it works. My question is how do I know when to use a .ToString() as opposed to a (string) as opposed to an "as String".
What is the difference between
String (S capital)
and
string (s small)
Where to use String and where string?
Both of these used same function. So why these two have been provided?
Secondly Why there is Not a constructor like:
String abc=new String("Hello");
How to format DateTime.ToString(????)Result should look like: 2010-02-05T10:36:26+10:00
View 2 RepliesI've a strange problem. We use Dutch and French lanuage on our site (nl-NL / fr-FR)I'm binding to a gridview and the strange thing is, the numeric value-saparator (dot) is not displaying well for French (fr-FR)ASP.NET
protected void gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label lbla_min_10 = new Label();
[code]...
I have an XElement object that contains about 120MB of data. The XML consists of approx 6000 elements of about 20kb each.
I am trying to call XElement.ToString() as I need to return the OuterXml in a webservice.
I am getting a System.OutOfMemoryException.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown:
at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)
at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)
at System.Text.StringBuilder.Append(Char[] value, Int32 startIndex, Int32 charCount)
at System.IO.StringWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.Xml.XmlEncodedRawTextWriter.FlushBuffer()
at System.Xml.XmlEncodedRawTextWriter.WriteAttributeTextBlock(Char* pSrc, Char* pSrcEnd)
at System.Xml.XmlEncodedRawTextWriter.WriteString(String text)
at System.Xml.XmlEncodedRawTextWriterIndent.WriteString(String text)
at System.Xml.XmlWellFormedWriter.WriteString(String text)
at System.Xml.XmlWriter.WriteAttributeString(String prefix, String localName, String ns, String value)
at System.Xml.Linq.ElementWriter.WriteStartElement(XElement e)
at System.Xml.Linq.ElementWriter.WriteElement(XElement e)
at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
at System.Xml.Linq.XNode.GetXmlString(SaveOptions o)
at System.Xml.Linq.XNode.ToString()
I have the same data in an XmlDocument and can call XmlDocument.OuterXml without a problem. I can also call XElement.Save() to save the XML to a file without a problem.
I have deployed my asp.net application in my hosting provider they are from US... I have one filed in which i have wriiten Datetime.now.tostring() it saves in Database table it save 11/11/2010 5:20:47 AM
View 17 RepliesWhen I run the following debugging code it writes out credits:0
Dim MembershipUser As MembershipUser = Membership.GetUser()
Dim UID As String = MembershipUser.ProviderUserKey.ToString
SQL = "SELECT SUM(Credits) As Credits FROM Credits WHERE " & _
"DateDiff(m, [DateTime], GETDATE()) < 6 AND [UserID]=@UserID;"
cmd = New SqlCommand(SQL, Conn)
cmd.Parameters.Add(New SqlParameter("@UserID", UID))
DataReader = cmd.ExecuteReader()
If DataReader.HasRows Then
Do While DataReader.Read
[Code]....
after my grid view updates a record I would like to run some code, I have tried to use SelectedDataKey.Value.ToString() to get the datakey. However it is null, the record updates so the value must be stored somehow?
View 1 RepliesBookmarkA.Title = Me.head.Page.Title.ToString()
I tried the above one in order to get the page title but I failed ! What I need to do ?
Me.head.Page.Title.ToString() did't get the value !
I have created an asp.net site with anonymous access turned off. Its for an internal (intranet) system which uses User.Identity.Name.ToString() to get the users login windows ID and then displays some records from a datagrid depending on their login ID. Is this secure? Also i am struggling to workout how best to store the result of User.Identity.Name.ToString() as I am not keen on storing it in a hidden text field and would rather not call it all the time unless this is the best way?
View 3 RepliesWell, I'm working with
Response.Output.Write(myReader[...].ToString)
and I'd like to output the data in 2 columns.
For instance the dataReader gets the following data: "1", "2", "3", "4" which will result in
1
2
3
4
but I'd like to have it like (in columns)
1 | 2
3 | 4
The Html code would be like
[Code]....
it would result in something like
[Code]....
But I'm working with an array that supplies the DataReader with what it should read, so I cannot write the code as above.
foreach (string strArr in outputLst)
I have a situation where I need to display the time in 24hr clock mode rather than 12hr mode. Is there a way to do this?
I need it to just display the the Hours & Mins e.g. 13:42. AM or PM is optional.
I have a web page which has few comments box which multi line asp text boxes. When i submit the page, i pass all the data as Server.UrlDecode(Request.Form.ToString()). Before submitting it to DB and splitting the string based on & and manipulating the values.
But when the user types in & in the comment box, my string manipulation gets messed up and i am getting "Index outside the bound" error.
Is there any way to encode user typed & and manipulate it?
I have a text box in which one is supposed to Enter a number .But if a person enters Text I get errors when parsing to integer.
View 4 RepliesI have the following code in 'main.cs' file where I am checking for a condition
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form.Get("task") != null && Request.Form.Get("postToURL") != null &&
Request.UrlReferrer.ToString().Substring(0, 31).Equals("http://cs.astra.co.in:4040"))
{
ASCIIEncoding encoding = new ASCIIEncoding();
<SO ON>
Instead of checking for the URL [URL] in 'main.cs', Can I check for the same condition in the 'web.config' file ? If so, How can I do that ?? Is there any way to transfer the part -- Request.UrlReferrer.ToString().Substring(0, 31).Equals[URL] -- into the 'web.config' !!
[Code]....
MSAJAX: overrides of toString() and other Object methods do not propagate to derived classes
View 1 RepliesWhat is the use of FormsAuthentication.SetAuthCookie(Session["UserSession"].ToString(), false);
View 1 RepliesIm trying to take the example from this website http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/sql-server-2008-proximity-search-with-th and make it work on my site. Its this part im having troubles with
[Code]...
here is my code from my function that doesnt work.
[Code]...
Any suggestions on how to get it to work? it fails at rdr = cmd.ExecuteReader(); im also worried it will also fail at ZipCodes.Add(rdr["h.*"].ToString());
What is the difference between "" and " " For which one i can use string.Empty.
View 2 RepliesIs there any way to use the DateTime.ToString() method to display the meridiem of the time portion as "A.M." instead of "AM"? I tried using the mask "t.t." but this just outputs "A.A."
View 2 RepliesI m facing some problem. i m not passing Dynamic string through query string..
I m using this code
string abc = "CPCB_" + TextBox1.Text + "_" + TextBox2.Text;
Response.Write("<script>window.open('xml.aspx?Flag=3&date='+abc,target='new');</script>");