473,573 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# Passing datasets in ASP

Hello if anyone can help me with this I will be very grateful.

I have a working version of this program as a windows application, when
I try to port it over to c# ASP.NET I can't make it work.

The program works in the following way.

Uploads a file to the server. (works)
Populates a dataset (works)
Passing the dataset to another class (doesn't work)

The problem comes when I try to access this dataset from another class.
I receive the error message

"NullReferenceE xception was unhandled by user code"

It occurs on the following line:

numberRows = Convert.ToInt32 (dsBarcodesToCh eck.Tables

Dataset is declared using the following code:

public DataSet dsBarcodesToChe ck = new DataSet();

I have included the entire program below. It is worth noting that the
public string test does seem to pass okay, the dataset doesn't.

Thanks for any help you can offer
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Xml;
using System.Threadin g;
using System.Data.Odb c;

public partial class _Default : System.Web.UI.P age
{
public int[] valueArray;
public DataSet dsBarcodesToChe ck = new DataSet();
public string Test;
public struct returndata
{
public string iclass;
public string ivendor;
public string istyle;
public string icolour;
public string isize;
public string ides;
public string ifound;
}
public void BarcodeLookup()
{
//Console.WriteLi ne("T" + Thread.CurrentT hread.Name + "-S" +
DateTime.Now.To LongTimeString( ));

returndata rd = new returndata();
DataSet ds = new DataSet();

string bar, upc, chk, strSQL, strConn;
int numberRows;
long RowsInQueryResu lt;

bar = "NotSet";
Test = "SETOKAY";

numberRows =
dsBarcodesToChe ck.Tables["BarcodesToChec k"].Rows.Count;

for (int looper = 1; looper < numberRows; looper++)
{
if
(dsBarcodesToCh eck.Tables["BarcodesToChec k"].Rows[looper]["ThreadAcce sse
d"].ToString() == "N")
{

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Rows[looper]["ThreadAcce ssed
"] = "Y";
bar =
dsBarcodesToChe ck.Tables["BarcodesToChec k"].Rows[looper]["Barcodes"].ToS
tring();

upc = bar.Substring(0 , 12);
chk = "";

if (bar.Length == 13)
{
chk = bar.Substring(1 2, 1);
}

strConn = "dsn=SYSBLON;ui d=GUEST;pwd=gue st;";
strSQL = "SELECT * FROM IPUPCXF where UUPD = '" + upc +
"' AND UECK = '" + chk + "'";
System.Data.Odb c.OdbcDataAdapt er da = new
OdbcDataAdapter (strSQL, strConn);
da.Fill(ds, "tblXref");

RowsInQueryResu lt = ds.Tables["tblXref"].Rows.Count;
rd.ifound = "false";

if (RowsInQueryRes ult > 0)
{
rd.iclass =
ds.Tables["tblXref"].Rows[0]["UCLS"].ToString();
rd.ivendor =
ds.Tables["tblXref"].Rows[0]["UVEN"].ToString();
rd.istyle =
ds.Tables["tblXref"].Rows[0]["USTY"].ToString();
rd.icolour =
ds.Tables["tblXref"].Rows[0]["UCLR"].ToString();
rd.isize =
ds.Tables["tblXref"].Rows[0]["USIZ"].ToString();
rd.ides =
ds.Tables["tblXref"].Rows[0]["UDES"].ToString();
rd.ifound = "true";
}

//Console.WriteLi ne("T" + Thread.CurrentT hread.Name +
"-" + DateTime.Now.To LongTimeString( ) + "-" + rd.iclass + "-" +
rd.ivendor + "-" + rd.istyle + "-" + rd.icolour + "-" + rd.isize + "-" +
rd.ides + "-" + rd.ifound);
ds.Tables["tblXref"].Clear();
}
}
}
public void Page_Load(objec t sender, EventArgs e)
{

}
public void UploadFile_Clic k(object sender, EventArgs e)
{
loadFile();
}
public void loadFile()
{
DataRow myRow;
string strFileName = FileUpload1.Pos tedFile.FileNam e;
strFileName = System.IO.Path. GetFileName(str FileName);
FileUpload1.Pos tedFile.SaveAs( "C:/Inetpub/BarcodeChecker/" +
strFileName + "");
Label1.Text = "Your file: " + strFileName + " has been uploaded
successfully";
string XmlFile;

XmlFile = "C:/Inetpub/BarcodeChecker/" + strFileName + "";

FileStream fstr = new FileStream(XmlF ile, FileMode.Open,
FileAccess.Read );

XmlTextReader reader = new XmlTextReader(f str);

string name;
string value;

dsBarcodesToChe ck.Tables.Add(" BarcodesToCheck ");

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Columns.Add("B arcodes");

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Columns.Add("C lass");

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Columns.Add("V endor");

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Columns.Add("S tyle");

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Columns.Add("C olour");
dsBarcodesToChe ck.Tables["BarcodesToChec k"].Columns.Add("S ize");

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Columns.Add("D escription");

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Columns.Add("T hreadAccessed"
);

while (reader.Read())
{
if (reader.Name.To String() == "Data")
{
reader.Read();
name = reader.Name.ToS tring();
value = reader.Value.To String();
if (value.Length > 0)
{
myRow =
dsBarcodesToChe ck.Tables["BarcodesToChec k"].NewRow();
myRow["Barcodes"] = value;
myRow["ThreadAccessed "] = "N";

dsBarcodesToChe ck.Tables["BarcodesToChec k"].Rows.Add(myRow );

}
}
}
Label1.Text =
dsBarcodesToChe ck.Tables["BarcodesToChec k"].Rows.Count.ToS tring();
fstr.Close();
Test = "testing";

GridViewer.Data Source = dsBarcodesToChe ck;
GridViewer.Data Member =
dsBarcodesToChe ck.Tables["BarcodesToChec k"].TableName.ToSt ring();
GridViewer.Data Bind();
}

public void CheckBarcodes_C lick(object sender, EventArgs e)
{
int numberRows;
string lclTesting;
lclTesting = Test;
numberRows =
Convert.ToInt32 (dsBarcodesToCh eck.Tables["BarcodesToChec k"].Rows.Count.T
oString());
for (int t = 0; t < 2; t++)
{
Thread thread = new Thread(new ThreadStart(Bar codeLookup));
thread.Name = Convert.ToStrin g(t);
thread.Start();
}
}
}


*** Sent via Developersdex http://www.developersdex.com ***
Jan 30 '06 #1
0 1533

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4743
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing around chunks of data in DataTables/DataSets, simply because that was the format that they were in when the data was taken from the database. Now,...
25
5036
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business Logic Layer (BLL) and User Interface Layer (UIL). The problem I found with this was circular referencing...
4
2963
by: Gr8North | last post by:
I'm relatively new to .Net, and would appreciate a little assistance. I have multiple datasets attached to individual grids on individual tabs on a form. I would like to have a series of generic functions such as SaveChange, RejectChanges, passing a grid and related dataset. As the datasets are different types, I'm passing them as an...
22
25564
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet =...
12
5311
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and...
0
834
by: Alexis | last post by:
Hello, I am working on an application that usues lookup data. I loaded that Data as Datasets on the Application Object. The webservices calls a dll that handles the business rules. This dll is the one that is going to use the Datasets. My Questions from the performance point of view are: Is Loading the Datasets on the Application object...
11
2535
by: Peter M. | last post by:
Hi all, I'm currently designing an n-tier application and have some doubts about my design. I have created a Data Access layer which connects to the database (SQL Server) and performs Select, update, delete and inserts. I use dataset objects to pass data to and from the DAL. In my GUI (windows forms), I use databinding to bind controls...
2
2626
by: grawsha2000 | last post by:
Greetings, I am developing this N-tier business app. The problem I'm facing is when I try to pass business objects (employees, dept..etc) from business tier to data tier,i.e., the add method in the data tier expects business object from the business tier, I get an error saying: Can not covert businesslayer.emp to businesslayer.emp
4
5917
by: John Sheppard | last post by:
Hello there I was wondering if anyone could help me, I am trying to pass a typed dataset to a dialoged child form by reference. I have binding sources sitting on the child form. So to refresh them I just set their datasource. I am guessing this is probably what is causing the problem. Is there a better way to do this? Anyway this all...
1
1101
by: Ilyas | last post by:
Hi all What are the best practises for passing custom objects to and from from services? In particular: 1)Should datasets be passed, or custom objects be passed? 2)When it comes to passing collections of objects what options are there? Should datasets be used here or should a generic list collection be used instead?
0
7747
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7670
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7987
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7740
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6363
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5557
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3706
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2167
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.