.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Empty value in string for streamwriter

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

From my other post i get a result from a query, the query gives some values.
I want to write the values to a file, but it is possible that one of the values is empty, when I try to write it with a empty value (for instance if CList.value2 is empty) then I get a Null error. how can i just write the entire record, including the empty on (cause the fil is a csv file).

So how can i avoid the Null error?



If Not String.IsNullOrEmpty(tbFilenaam.Text) Then
                Dim oStWriter As New StreamWriter(Server.MapPath(tbFilenaam.Text))
                For Each CList In retVal1
                    oStWriter.WriteLine(CList.value1 + ";" + CList.value2)
            End If

View Complete Post

More Related Resource Links

Dropdown menu - Null or empty string??


I have drop dowm menu as follow.

<asp:ListItem Value="">none</asp:ListItem>
<asp:ListItem Value="STO">Stock</asp:ListItem>
<asp:ListItem Value="ORD">Order</asp:ListItem>

If I chose none, it stores data as "Null"

If I Query the data as below, I don't get the data has value of "Null"

SELECT tabale From type Where type <> STO or type <> ORD

I get data that has empty string but not Null.

Here is my question.

1, How do I write dropdown menu value in oder to get empty string instead of Null?
I did <asp:ListItem Value="">none</asp:ListItem> but this stores Null.

2, Why this Query won't pick up Null?
SELECT mytabale FROM type WHERE type <> STO or type <> ORD

Thank you for your help.

VS2005 calling VS2010 asmx service returns empty string


Anyone have any experience with this?

We are using VS 2005 for the front end, and vs 2010 for the web services part (asmx), not wcf yet.


Web service works just like the vs2005 when run locally, no problems.


Connecting to it from a test app returns an empty string. Connecting to a 2005 app doesn't!

Anyone run into this before or have a suggestion? Surely vs 2005 can connect to web services from a later version?






error in MVC2 on empty string form fields which are required: "This property cannot be set to a null

In model I have:[DisplayName("ISBN")] [Required(ErrorMessage = "ISBN is required.")] [StringLength(50, ErrorMessage = "ISBN book must have max {1} chars.")] [DisplayFormat(ConvertEmptyStringToNull = false)] public string isbn { get; set; }But when I submit form with empty field ISBN I have an error - ConstraintException: This property cannot be set to a null value.I have find that other people have the same problem and they say that debbugger in VS2010 works wrong - yes ?http://p2p.wrox.com/book-professional-asp-net-mvc-2/79788-constraintexception-unhandled-user-code.html#post259245http://efreedom.com/Question/1-3129080/Server-Side-Validation-REQUIRED-String-Property-MVC2-Entity-Framework-Workhttp://mvcmusicstore.codeplex.com/workitem/6604

Varchar string to int - how to convert empty cells to nulls

Hi, I have a large table from which I want to convert certain columns from varchar to int while loading the table to another table. However, I run into problems when the input column contains empty cells. The SSIS data conversion data flow item can't handle these so I tried the script component. With the script component I can convert these empty cells to zeros but after that I'd need to use SQL update to update the zeros to nulls which in the case of a large table with over 3 million rows takes unnecessarily long. So, is there another way?

replace empty string with value if it is empty in ssrs

I need to place a "Days Not Calculated" of the string is empty, if it is not empty then a need to use the days calculated and put "days old" on the end of the number....SSRS 2K5 iif (Fields!AGE.Value, "", "Days Not Calculated")& " Days Old "

Caml returns table with column, whose value is empty string always, but it's not

I wrote caml query   SPSiteDataQuery query = new SPSiteDataQuery(); query.ViewFields = @"<FieldRef Name='Title' /><FieldRef Name='cmAssignedTo' Nullable='TRUE' />" + "<FieldRef Name='cmDueDate' Nullable='TRUE' /><FieldRef Name='Author' /><FieldRef Name='cmStatus' />" + "<FieldRef Name='cmControler' Nullable='TRUE' /><FieldRef Name='cmControlers' Nullable='TRUE' />" + "<FieldRef Name='FileDirRef' /><FieldRef Name='File_x0020_Type' /><FieldRef Name='cmIcon' /><FieldRef Name='cmPackageGuid' />" ; query.Webs = string .Format("<Webs Scope='{0}' />" , searchScope); query.Lists = "<Lists ServerTemplate='10553'/>" ; Fields cmAssignedTo, cmControler and cmControles return always "", but they include users! Definition of these fields is similar:   <Field xmlns="http://schemas.microsoft.com/sharepoint/" DisplayName="cmAssignedTo" StaticName="cmAssignedTo" Name="cmAssignedTo" ID="{B4B52176-1961-4b06-B7B4-C7DBB751A53F}" Type="User" List="UserInfo" ShowField="ImnName" Mult="TRUE" />   List, where i'm looking for in, includes 2 contenttypes. First one contains these

how to insert null or empty string to datetime var ?

hi i get data from xml file and sometime the date is empty. i have this code:     try { TimeTo = Convert.ToDateTime(R[15].ToString()); }         catch { TimeTo = null ; } but i got error because i cant insert null to datetime var what i can do ? thak's in advance

if NULL in database table - display empty string?


I have a table in an Sql Server Database from which I want to fetch data to a form. 

[Headline] [varchar](max) NULL,
[Text] [varchar](max) NULL,

[ID] [int] IDENTITY(1,1) NOT NULL,

[Headline] [varchar](max) NULL,

[Text] [varchar](max) NULL,

I want to check both Headline and Text to see if they are null, and if so display an empty string each for them. I've looked at some tutorials but don't yet understand really how to use it. DBNull? DataRow.IsNull? Something else? Can I check both Headline and Text at the same time or do I need do check them separately?



What is the difference between ""  and " "

For which one i can use string.Empty.

How do you specify an empty string in XAML?



For an application I am working on, I am keeping some of the strings for the UI in a ResourceDictionary, which is defined in XAML, like so:


<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlnsTongue Tiedystem="clr-namespaceTongue Tiedystem;assembly=mscorlib"

    <systemTongue Tiedtring x:Key="String1">String 1</systemTongue Tiedtring>
    <systemTongue Tiedtring x:Key="String2">String 2</systemTongue Tied

Forms Library Changed event and Validation event returns empty string on date picker


Hi there,

I'm trying to do date validation on a date and time picker through code (i want to make sure that the date is later than today and that the next date is at least one day later than that).

But when i try to get the value in the chagned event, i keep getting empty string as value.

What am i doing wrong here??

This is the code:

public void LeaveRequestFrom_Changed(object sender, XmlEventArgs e)
      // Write your code here to change the main data source.
      XPathNavigator xroot = MainDataSource.CreateNavigator();
      XPathNavigator fromdate = xroot.SelectSingleNode(
        "/my:myFields/my:LeaveRequestFrom", NamespaceManager);

      if (fromdate.Value != "")
        //Make sure the from date is in the future
        if (DateTime.Parse(fromdate.Value) < DateTime.Today.AddDays(1))


The world

help inserting an empty string and a default date thru a stored procedure


I want to insert an empty string in a nvarchar field and a default date like a base date in a datetime field inside a stored procedure without passing it the value thru a parameter

how is this done?

INSERT INTO deals_SoldItems (











this dont work



Webservices with NULL or Empty String


Hi ,

We have developed a Webservice which returns data in the form of xml to client. When we access the webservice from our brower, we were able to see the message with empty string. But in SSRS dataset designing we dont see column at all.


For example:- Webservice developed  returns the XML data to client.When we bound this webservice has datasource for dataset, we dont see column in dataset which contains empty string or null.

How can i have column present in dataset in though XML element value is null or empty.

Like DOB in employee xml is sent to client. But this XML contain DOB with empty data like <DOB></DOB>. Since DOB xml element is empty we could not see this DOB column in dataset of Report. How can show tht DOB column in dataset



ObjectDataSource NULL to Empty String


I have pass following SQL Query to the through ObjectDataSource

SELECT     RequesterID, CompanyID, Name, emailID, Department, JobTitle, MobileNo, LandLine, Ext, Remarks
FROM         Requester
Where Name Like @Name + '%'

And I am passing parameter through QueryString and My idea is like when empty string is pass it should show me all records but when I am passing empty string ObjectDataSource is making NULL and I am not getting desire result

Kindly can somebody help me on that. It is okay if you change query of help me on objectDataSource.

How to store NULL instead of empty string in LinqToSQL scenario


Technology used : VS2008, VB.NET, LinqToSQL, BindingSource

I used LinqToSQL to create a detailsform. So I have a Textbox bound to a Varchar column in the dababase. When I created a record with the form it stores some columns as NULL values which is perfect. When I change the value of the textbox to something and do a db.SubmitChanges() the value is stored. 

However, when I make the textbox empty and save, the value in the database is an empty string. I want it to be NULL. How can i achieve this?


How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt

Connestion string create any database server

This links important to how to create connection string to any data base sever.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend