Thanks a lot Imar, that was it!
Adios
Phil
-----Original Message-----
From: Imar Spaanjaars [mailto:Imar@S...]
Sent: 15 May 2002 16:14
To: ASPX_Professional
Subject: [aspx_professional] Re: Object reference not set to an instance
of an object
Hi Phil,
It looks like you mixed up your table definitions in your DataSet.
When you add the table, you name it Brand
-- oDA.Fill(oDs,"Brand");
When you refer to it, you use tblBrand
-- DataRow oDR = oDs.Tables["tblBrand"].NewRow();
The DataSet only contains a table called Brand, so it can't find tblBrand.
Change one of the names to the other, and your problem should be solved.
HtH
Imar
At 04:01 PM 5/15/2002 +0100, you wrote:
>Hi all,
>
>I have a C# class function that takes 5 parameters wheich is called from a
>web page that is throwing
>an error thus: "Object reference not set to an instance of an object"
>
>here's how I try and use it from the web page:
>
>myNamespace.ADOFunctions test = new myNamespace.ADOFunctions();
>test.AddBrandDBEntry("filename", "filetype", ".jpg", 1024, "descr");
>
>here's the class
>
>using System;
>using System.Configuration;
>using System.Data;
>using System.Data.OleDb;
>
>namespace myNamespace
>{
> /// <summary>
> /// Summary description for ADOFunctions.
> /// </summary>
> public class ADOFunctions
> {
>
> public ADOFunctions()
> { //constructor
> //class initialising code here
> }
>
> public string OLEConnectionString()
> {
> return
ConfigurationSettings.AppSettings["OLEDSN"];
> }
>
> public void AddBrandDBEntry(string FileName, string
>FileType,
>
>string FileExtension, int FileSize,
>
>string Description)
> {
>
> //the sql statement
> string sSQL = "SELECT * from tblBrand";
>
> //the connection object
> OleDbConnection oCn = new
>OleDbConnection(OLEConnectionString());
> oCn.Open();
> OleDbDataAdapter oDA = new
>OleDbDataAdapter(sSQL,oCn);
> DataSet oDs = new DataSet();
> oDA.Fill(oDs,"Brand");
>
> //create the Data Row
> DataRow oDR = oDs.Tables["tblBrand"].NewRow();
>
> //Populate the datarow with values
> oDR["Filename"] = FileName;
> oDR["Filetype"] = FileType;
> oDR["FileExtension"] = FileExtension;
> oDR["Filesize"] = FileSize;
> oDR["Description"] = Description;
>
> //Add the datarow to the dataset
> oDs.Tables["tblBrand"].Rows.Add(oDR);
>
> //Use the Command Bulder object to generate Insert
>Command dynamically
> OleDbCommandBuilder oCB = new
>OleDbCommandBuilder(oDA);
>
> //Update the DB with values from Dataset with the
>Data Adapter
> oDA.Update(oDs,"Brand");
> //Clean Up
> }
>
>
> }
>}