Showing posts with label dataset. Show all posts
Showing posts with label dataset. Show all posts

Wednesday, March 28, 2012

Having problems reading a record

I have a strongly typed dataset. I'm trying to read a record. I have the following

Dim ResourceAdapter As New ResourcesTableAdapters.ResourcesTableAdapter
Dim dF As Data.DataTable = ResourceAdapter.GetDataByResourceID(sID)
Dim RecResource As Resources.ResourcesRow

strBody = "The following link has been reported as broken. "
strBody = strBody & "Please verify before deleting." & Chr(10)
strBody = strBody & "Category: " & RecResource.Category & Chr(10)
strBody = strBody & "Title: " & RecResource.Title & Chr(10)
strBody = strBody & "URL: " & RecResource.URL & Chr(10)

where the GetDataByResourceID(sID) method returns a single row. I get the following error on the core line in bold:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 124: strBody = "The following link has been reported as broken. "
Line 125: strBody = strBody & "Please verify before deleting." & Chr(10)
Line 126: strBody = strBody & "Category: " & RecResource.Category & Chr(10)
Line 127: strBody = strBody & "Title: " & RecResource.Title & Chr(10)
Line 128: strBody = strBody & "URL: " & RecResource.URL & Chr(10)

What am I doing wrong?

Diane

Resources.ResourcesRow is nothing (null).

That is why you are getting the error.

|||

You never assign a value to RecResources that is why you are getting the error. Try something like this

Dim dF As Data.DataTable = ResourceAdapter.GetDataByResourceID(sID)
Dim RecResource As Resources.ResourcesRow = dF.Rows(0)|||

That makes sense, thank you. That fixed it.

Diane

sql

Friday, February 24, 2012

Handling Dataset in Stored Proc.

Hi,

I want to create and populate a dataset from store procedure with following to querires & return the dataset as a result.

Select * from billmain where billno = 12

Select * from billdetails where billno = 12

I am currently performing this task aa a resultset. Now I want to use Dataset. Anybody can send me sample sp which returns dataset as a execution of the sp.

Nilkanth Desai

A simple select statement would do. Call the stored procedure from your ADO.NET code and store the results of this stored procedure in a DataSet object.

CREATE PROCEDURE SelectTable @.billNo int

AS

SELECT columnName FROM Table WHERE billno=@.billNo

|||

Hi,

Thanks fpr your Reply. This is working fine when I call it from my ADO.NET Code. But If I want to trf. Dataset as a return result of the said stored proc. where I will be doing multiple select in more then one table. So if I call it only once I can complete all task in a single call. In addition I want to marshal the job to server. So, In this case now tell me what should I do.I don't want to use CLR-Integrated stored procedure. In this case can How can I handle Dataset in above mentioned manner in a standard T-SQL stored procedure?

Nilkanth Desai

|||

You can return more than one SQL Server resultsets from a single stored procedure, see the example below.

Chris

CREATE PROCEDURE SelectTable @.billNo int

AS

SELECT columnName

FROM BillMain WHERE billno=@.billNo

SELECT columnName

FROM BillDetails WHERE billno=@.billNo

GO

handle store procedure return 2 table

I have a sp that will do two select from two table. now, can datareader read both table or only dataset can? if datareader can? how to handle it?In .NET 2.0 you can return multiple datasets with a datareader. You use the NextResult() method to get the next set. Seehere.