0

Hi guys

I think this is simple question,now Iam frustrated coz i could not find the error.Below I mention the coding I wrote.I Highlighted the text where exception occurs.Exception is "Object reference not set to an instance of an object."(Null ReferenceException)
Pls help me

private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog File_Open = new OpenFileDialog();
            File_Open.Filter = "Excel Files (*.xls)|*.XLS";
            File_Open.ShowDialog();
            string path1 = File_Open.FileName.ToString();
            Bizz B = new Bizz(path1);
            DataSet D1 = B.show_excel();
            DataRow[] foundRows;
            foundRows = D1.Tables[0].Select("ShopCode IS NOT NULL");
           
         
            B.T.Columns.Add("SHOP_CODE");
            B.T.Columns.Add("SHOP_NAME");
          
    

            DataRow row = null;
            for (int i = 0; i < foundRows.Length; i++)
            {
                row = B.T.NewRow();
                row["SHOP_CODE"] = get_DataValidate(foundRows[i]["ShopCode"].ToString());
                row["SHOP_NAME"] = foundRows[i]["ShopName"];
                T.Rows.Add(row);

            }
public class Bizz
    {
        public string Path;
        public DbConnection dbconn;
        public DataTable T;

        public Bizz()
        {
            Path = null;
            dbconn = new DbConnection();
            DataTable T = new DataTable();
        }

        public Bizz(string path)
        {
            Path = path;
            DataTable T = new DataTable();
            dbconn = new DbConnection();
                     
        }

Thanks

4
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by LizR
0

Dont you need to set some more details about datatable before its usable?

When you've created "B" and you debug it, what does it show you?

0

Does your path variable has a value?
Normally you do something like this :

if (dlg.ShowDialog() == DialogResult.OK)
            {
                //get your path here
            }
            dlg.Dispose();
0

I can't follow this either - I see

B.T.Columns.Add("SHOP_CODE");

is in red so I assume that means that is where you get the error?

I don't see where SHOP_CODE is declared.

(and remember, I am new to C# and programming in general so don't be too harsh if I missed something obvious)

0

"SHOP_CODE" is a string.. it wouldnt need to be.

However, debugging it and watching what happens after B is made, and checking what you see as B is what you thought would seem very simple and should provide most of the answer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.