473,411 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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

"NullReferenceException was unhandled by user code"

It occurs on the following line:

numberRows = Convert.ToInt32(dsBarcodesToCheck.Tables

Dataset is declared using the following code:

public DataSet dsBarcodesToCheck = 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.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Threading;
using System.Data.Odbc;

public partial class _Default : System.Web.UI.Page
{
public int[] valueArray;
public DataSet dsBarcodesToCheck = 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.WriteLine("T" + Thread.CurrentThread.Name + "-S" +
DateTime.Now.ToLongTimeString());

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

string bar, upc, chk, strSQL, strConn;
int numberRows;
long RowsInQueryResult;

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

numberRows =
dsBarcodesToCheck.Tables["BarcodesToCheck"].Rows.Count;

for (int looper = 1; looper < numberRows; looper++)
{
if
(dsBarcodesToCheck.Tables["BarcodesToCheck"].Rows[looper]["ThreadAccesse
d"].ToString() == "N")
{

dsBarcodesToCheck.Tables["BarcodesToCheck"].Rows[looper]["ThreadAccessed
"] = "Y";
bar =
dsBarcodesToCheck.Tables["BarcodesToCheck"].Rows[looper]["Barcodes"].ToS
tring();

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

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

strConn = "dsn=SYSBLON;uid=GUEST;pwd=guest;";
strSQL = "SELECT * FROM IPUPCXF where UUPD = '" + upc +
"' AND UECK = '" + chk + "'";
System.Data.Odbc.OdbcDataAdapter da = new
OdbcDataAdapter(strSQL, strConn);
da.Fill(ds, "tblXref");

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

if (RowsInQueryResult > 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.WriteLine("T" + Thread.CurrentThread.Name +
"-" + DateTime.Now.ToLongTimeString() + "-" + rd.iclass + "-" +
rd.ivendor + "-" + rd.istyle + "-" + rd.icolour + "-" + rd.isize + "-" +
rd.ides + "-" + rd.ifound);
ds.Tables["tblXref"].Clear();
}
}
}
public void Page_Load(object sender, EventArgs e)
{

}
public void UploadFile_Click(object sender, EventArgs e)
{
loadFile();
}
public void loadFile()
{
DataRow myRow;
string strFileName = FileUpload1.PostedFile.FileName;
strFileName = System.IO.Path.GetFileName(strFileName);
FileUpload1.PostedFile.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(XmlFile, FileMode.Open,
FileAccess.Read);

XmlTextReader reader = new XmlTextReader(fstr);

string name;
string value;

dsBarcodesToCheck.Tables.Add("BarcodesToCheck");

dsBarcodesToCheck.Tables["BarcodesToCheck"].Columns.Add("Barcodes");

dsBarcodesToCheck.Tables["BarcodesToCheck"].Columns.Add("Class");

dsBarcodesToCheck.Tables["BarcodesToCheck"].Columns.Add("Vendor");

dsBarcodesToCheck.Tables["BarcodesToCheck"].Columns.Add("Style");

dsBarcodesToCheck.Tables["BarcodesToCheck"].Columns.Add("Colour");
dsBarcodesToCheck.Tables["BarcodesToCheck"].Columns.Add("Size");

dsBarcodesToCheck.Tables["BarcodesToCheck"].Columns.Add("Description");

dsBarcodesToCheck.Tables["BarcodesToCheck"].Columns.Add("ThreadAccessed"
);

while (reader.Read())
{
if (reader.Name.ToString() == "Data")
{
reader.Read();
name = reader.Name.ToString();
value = reader.Value.ToString();
if (value.Length > 0)
{
myRow =
dsBarcodesToCheck.Tables["BarcodesToCheck"].NewRow();
myRow["Barcodes"] = value;
myRow["ThreadAccessed"] = "N";

dsBarcodesToCheck.Tables["BarcodesToCheck"].Rows.Add(myRow);

}
}
}
Label1.Text =
dsBarcodesToCheck.Tables["BarcodesToCheck"].Rows.Count.ToString();
fstr.Close();
Test = "testing";

GridViewer.DataSource = dsBarcodesToCheck;
GridViewer.DataMember =
dsBarcodesToCheck.Tables["BarcodesToCheck"].TableName.ToString();
GridViewer.DataBind();
}

public void CheckBarcodes_Click(object sender, EventArgs e)
{
int numberRows;
string lclTesting;
lclTesting = Test;
numberRows =
Convert.ToInt32(dsBarcodesToCheck.Tables["BarcodesToCheck"].Rows.Count.T
oString());
for (int t = 0; t < 2; t++)
{
Thread thread = new Thread(new ThreadStart(BarcodeLookup));
thread.Name = Convert.ToString(t);
thread.Start();
}
}
}


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

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

Similar topics

3
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...
25
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...
4
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...
22
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...
12
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...
0
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...
11
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,...
2
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...
4
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...
1
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.