.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

How to check if DataTable row is empty

Posted By:      Posted Date: October 05, 2010    Points: 0   Category :ASP.Net


Im using "string user = Database.GetMostRecentReply(id).Rows[0][2].ToString();" to get the username from the most recent reply in my forum.

But how do I check if the row is empty? Im using a try catch at the moment, but there must be a better way to do this.


View Complete Post

More Related Resource Links

How to check for null/empty strings on dynamic objects?


What is the proper way to check for null or empty strings on dynamic objects? This is the only solution I've found so far:

if (admin.PasswordHash.GetType() == typeof(DBNull) || admin.PasswordHash == string.Empty)

If the field is null, the object returned is DBNull.Value, but if the field is empty string, it's return as a System.String object. This makes it impossible to do regular "admin.PasswordHash == DBNull.Value" check, as that will fail whenever the field has been set to empty string. Is my example the right (and only) way to go?

how to check if a Dataview is empty?

I am having trouble with the syntax to check if my Dataview is empty.  If it is empty then the next line when I try draw information from it generates an error. How can I fix this?Dim ProjectDV As DataViewDim arg As New DataSourceSelectArgumentsProjectDV = SqlDataSource1.Select(arg)   If ProjectDV.Count <> 0 ThenpicAd.Text = LCase(ProjectDV(0)("Ad"))End If  

Binding DataGrid to empty DataTable

Hi, I'm very much new to WPF and am finding it a bit tricky to find my way in the mass of (not always great) documentation. Right now I'm struggling to get the grid to display it's UI when bound to an empty datatable. In my XAML: <DataGrid Name="grid" ItemsSource="{Binding}" />  In my code-behind (MainWindow constructor, following InitializeComponent): var dt = new DataTable(); dt.Columns.Add("col1"); dt.Columns.Add("col2"); //var r = dt.Rows.Add("toto", "tata"); grid.DataContext = dt; If I comment out the line that adds a row to the table, all is well -- the grid generates columns and displays UI. But if the table is empty, the grid renders a thin horizontal white rectangle with no column names and it doesn't seem possible to interact with this at all. As it happens, I want the grid to be empty by default, so I need to somehow get the grid to play along. If anyone knows why this happens and what to do to solve it, I'd much appreciate the help!

When to check if something Is Nothing? How do you check an empty textbox?


I currently do something like...

If TextBox1.Text Is Nothing OR Trim(TextBox1.Text) = "" Then

' Do whatever

End If

Now I know this works.. but what is the right way to have this? I don't want to be checking something twice instead of just having it written out once.

Check for empty array?


How do i check for empty array?


If I write

If Not ls_filename.Length = 0 then


End If


I get object refernce set to null error

Check Empty WebPart Using JQuery


Hi All,

Is it possible to identify a empty webpart in the page?

For e.g, we have an annoucement webPart that has no item, The webpart will display an default OOB Message.

Our Requriement is to identify those empty webpart and hide them. Whether this is possible using JQuery/ Javascript?

Note: Solution should in either in JQuery or Javascript or any those OOB option. We should not do any Coding?

Please let me know whether this is possible?


Ganesh Moorthy S

Check if all members of MeasureGroupMeasures are empty

Is there a way to check if all members of MeasureGroupMeasures are empty in the MDX query?

Javier Guillen

Check Whether the grid view is empty or not



Hello all Members,

I am new to asp.net.

i don't know where to post this issue.

Problem that i am facing is,

I have a grid view bind with LINQdatasource control & i want to check whether it is empty or not.

How do i do this ?

and also, If it is empty, then i have to enable a button control on my form.

Please help me in this issue.

Thanks in advance.


Using trim to check element is empty in jQuery

Using trim method, one can also check element is empty or not.

Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

Check All with JQuery and a Asp.Net GridView

Display a Grid on the screen with a checkbox in each row. At the bottom of the page have "Check All" button.

Typically if I need to do anything interesting I use a template column. So my GridView will look like the one below (most other columns removed for readability). The only interesting point to note is the CssClass="ApprovalCheckBox" in the CheckBox ItemTemplate.

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

DataTable - Load from IDataReader - CreateDataReader - ReadXml WriteXml - Free ADO.NET Tutorials

The DataTable in ADO.NET 2.0 has been seriously beefed up and I absolutely love it. Not everything we consume deals with multiple resultsets and requires the ever popular DataSet. With the cool new features in the ADO.NET 2.0 DataTable, we can get many of the cool features in the DataSet without all the extra baggage and memory footprint particular to multiple resultsets.

Load DataTable from IDataReader

check box control


Hi ,

I have a three check box in my web form ,i need to choose only one check box, if i choose one check box

another 2 check box automatically unchecked

can i use jquery for check box

I thought this would be simple... Trying to create a login does an ajax check before submit


I have the standard .net login control that is working.  (Still learning .net after 15yrs of classic)

What I want to do is OnButtonClick run a javascript function (to do an ajax call to the db to check if login is valid or not) and if it returns true, then submit the form normally, else don't submit. The piece that I can't figure out, is how to correctly override the default click even to hit my JS routine and then submit the form properly afterwards.

Thanks ahead of time

how to check a textbox value in jquery?



I want to perform some action when an asp.net textbox value length is greater than 1 character. And for this I wanted to know how to write this check in jquery?

I have created a check like below-

if ($('[id=txtUserInput]').val().length > 2)
{ do some work...} 

But its giving me the following error

$("[id=txtUserInput]").val() is undefined

Can anybody let me know the right way of doing this?



Automatically redirect to HTTPS and check if SSL is active



I've set in the web.config:

    <!-- User Authentication -->
    <authentication mode="Forms">
      <forms loginUrl="~/Page/View/Content/Login.aspx" timeout="2880" requireSSL="true" />

This works fine. If there is no ssl connection, the login form doesn't continue. But I would like to check if ssl is active (in codebehind) and, if it's possible, to automatically the user to the https page if he's currently on http. (I could do this job by manually redirect with page.response("https://url.../login.aspx"); but this is not really generic. For example if the webapp is moved to another domain it doesn't work anymore... I'm looking for something like: FormsAuthentication.RedirectWithSSL(); or so... :D)


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