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

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

isdbnull() table adapter

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :ASP.Net

Hi, was hoping someone could help.  I have a sqltableadapter with a select query, and am trying to popluate textboxes from the data retrieved.  All is well until  I come to a null value.   I've tried to check for isdbnull, in an if statement. 

' usr is defined earlier

Dim strfirstname As String = ""

Dim usrinfo As New sqlTableAdapters.UserInfoTableAdapter

                Dim mydatatable As sql.UserInfoDataTable = Nothing

                mydatatable = usrinfo.GetDataByUserID(usr)

                If Not IsDBNull(mydatatable(0).FirstName) Then

                    strfirstname = mydatatable(0).FirstName
                    Label1.Text = strfirstname
                End If      ................

(goes on for more columns)

However, the page throws an error when it gets to a column with a null value:

Line 2068: get { Line 2069: try { Line 2070: return ((string)(this[this.tableUserInfo.FirstNameColumn])); Line 2071: } Line 2072: catch (global::System.InvalidCastException e) {


View Complete Post

More Related Resource Links

Table Adapter generates bad SQL under load

I have an application (ASP.NET 2.0/SQL Server 2005) which makes heavy use of table adapters for pulling records from SQL. Under heavy load, we get a lot of SQL Server Timeout errors. We have run a trace on SQL Server and it shows that several of the SQL statements being passed into SQL Server, from the Table Adapters, have bad SQL. For example, here is the SQL in one of the table adapters SELECT    HomeMsgID, messageName, messageHTML, messageText, populationID FROM        MyUCR_HomeMessages WHERE    (populationID IN                           (SELECT    populationID                             FROM          MyUCR_Population_CPID AS MyUCR_Population_CPID_1                             WHERE      (CPID = @CPID))) AND (isVisible = 1) AND (showDate <= @showDate) AND (removeDate >= @removeDate) I call it with the following: DateTime showDate = DateTime.Today; DateTime removeDate = DateTime.Today; myUCR_HomePageMsgsTableAdapters.MyUCR_HomeMessagesTableAdapter ta = new myUCR_HomePageMsgsTableAdapters.MyUCR_HomeMessagesTableAdapter(); myUCR_HomePageMsgs.MyUCR_HomeMessagesDataTable dt = new myUCR_HomePageMsgs.MyUCR_HomeMessagesDataTable(); ta.FillByCPID(dt, showDate, removeDate, CPID); What the SQL trace shows, when it fails, is this (notice the extra single quotes around the showDate, removeDate parameters): E000 exec sp_executesql N'SELECT    HomeMsgID, messageN

Dynamically fill query parameters in a table adapter ?

SO I have created an object data source on a page from a table adapter using the various Wizards in Visual Studio.Its meant to query a diary Database by a DateTime parameter called diaryDate. I want to query from a date Now to the next 14 days ahead.I want to display the entries in a Grid View when the page loads.So I'm a bit stuck now as to how to set the two query parameters date1 and date2. I want to set date1 = now() and date2 = now() + 14 days.How do I set those parameters when the page loads ?Should I have used the adapter Wizard approach of do I have to write all the code in the code behind page ??This is my datasource code'<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GET_nextTwoWeeks" TypeName="query_getNextTwoWeeksTableAdapters.diaryDatesTableAdapter"> <SelectParameters> <asp:FormParameter DefaultValue="" FormField="date1" Name="date1" Type="DateTime" /> <asp:FormParameter DefaultValue="" FormField="date2" Name="date2" Type="DateTime" /> </SelectParameters> <InsertParameters>

dataset table adapter commands



how i can disable generation of insert update delete select commands in tableadapter or how i can

remove all of these commands in dataset?


tank u in advance

stored procedure or table adapter commands


hi friends

in my windows application i used a dataset and populated it with tables by dragging tables from server explorer, and for each table's table adapter i added four stored procedures that i have created in sql server while dataset generator generates insert, update , select , delete commands for each table adapter. i want to know whick one is better, using stored procedure or using dataset generated commands?

tanks in advance


Using Table Adapter in Visual Studio to retrieve data


Hi, I have a profile of member to be displayed. I am using a dataset with all the data table adapter to retrieve the information from database. 

I have a memContact method which has NRIC and Number as a composition primary key. Thus, automatically, the table adapter has created a method called FindByICNum () for me. However, when I do the search to display the contents, i will only need to search by memberic instead. 

Is there anyway to change the table adapter query? 

Serialising Data Table returned from Table Adapter Fill method


I am having issues when attempting to serialise a datatable returned from a TableAdapter fill method created via the data set designer.

I have a server executable (which contains the dataset), a client executable and interface referenced by both for proxy purposes.

I guess this is to do with the designer's datatable actually deriving from a datatable (where it adds custom properties and events specific for the data retrieved by the tableadapter).  So I have temporarily made an ugly method of creating a standard new datatable and populating it with column and row data via enumerating the table from the adapter for its column and row data, but I don't want to have to do that!

Standard copy methods on the adapter's table does not work.  Whenever I try to get a datatable via remoting and it references the adapter's table, it returns a serializationerror syaing my server assembly cannot be found (well, only the server knows about these derived datatables so that s understandable).  I don't want to move the dataset into the commonly referenced assembly as that sounds like overkill and probably not good practice?


Adapter Design Pattern in C#, VB.NET

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Export Visio Database Table Names to Excel

If you use the Enterprise Architect edition of Microsoft Visio for data modeling regularly, then there is a good chance that at some point you've wanted to export just the table names into Excel. You might want to do this to map logical ERD entities to physical data model tables, track project status by entity, or track overlap between database versions.

Insert value using Table Value Functions

a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

Using jQuery to Filter Table Rows

The project is using the .net GridView control, so I had limited control over the output HTML code. Still, I think this code can work for most tables. One thing to notice: you should use the class "filterable" on your table or on one of its parents for the code to work.
First, we need a text box:

RadioButton Groups, Table Rows And NamingContainers in asp.net

The RadioButtonList. Very handy for inviting users to select just one item from a list although because of the screen real estate it takes up, used less and less in favour of the DropDownList. In plain HTML, the browser knows to enforce the unique selected value amongst a list of radio buttons because they all have the same value for their name attributes.

RadioButton Groups, Table Rows And NamingContainers

(In which AJAX-enhanced CheckBoxes become more useful than RadioButtons but inheritance saves the day, and a simple RadioButton-derived control establishes the purpose of a control's naming container)

The RadioButtonList. Very handy for inviting users to select just one item from a list although because of the screen real estate it takes up, used less and less in favour of the DropDownList. In plain HTML, the browser knows to enforce the unique selected value amongst a list of radio buttons because they all have the same value for their name attributes.

Building a 3-Tier App with Silverlight 3, .NET RIA Services, and Azure Table Storage

Silverlight 3, .NET RIA Services, and Windows Azure Services Platform makes a 3-tier Cloud application easier to build: Silverlight 3 as presentation tier, .NET RIA services as the business logic and data access tier, and Windows Azure Table as the data storage tier. The sample application in this article demonstrates the architecture with a simple Survey application with all these technologies working together from Windows Azure.

Temporary tables in SQL Server vs. table variables

When writing T-SQL code, you often need a table in which to store data temporarily when it comes time to execute that code. You have four table options: normal tables, local temporary tables, global temporary tables and table variables. I'll discuss the differences between using temporary tables in SQL Server versus table variables.

Import XML File to SQL Table

Here is a brief example of importing an XML file into SQL Server table. This is accomplished by using the BULK option of OPENROWSET to load the file, and then utilizing the XQuery capabilities of SQL Server to parse the XML to normalized table format. This example requires SQL server 2005 or SQL Server 2008.

First, the following XML is saved to XML file C:\Products.xml.

Adding the table row below a particular row.


What is the best method in jQuery to add an additional row to a table as the row below a particular row?

Checkboxes from data table


I have a data table that contains some values for Certifications.  This table can be updated in a different part of my application.  On the web page I am currently working on, I would like to have check boxes appear for every value in the data table.  I have been struggling with this trying to use a For Each loop and I cannot get it to work for anything.  Any suggestions? 

I am using the following Razor syntax to obtain my data (I know this works because I can display it in a WebGrid):


var db = Database.Open("MyConn");

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