Hello Frnds,

I have an application developed in ASP.Net(C#) and MS SQL, its working fine and fulfilling the requirements. Now the problem is I have a MS Access Database from where I have to read some data and feed it into ASP.Net form and then save it to MS SQL Database. Keep in mind i can't convert the MS Access DB to SQL directly as I need only few data from the MS Access DB.

Well I tried to connect the MS Access DB with an ASP Page and stored the particular data in session variable and tried to feed data from session to textbox of the form but I got error message. The message is following:

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


And Now I have an idea, I want to connect the MS Access DB directly from ASP.Net Page and then will feed up the text boxes in the form and save it to the SQL DB. But I am not sure that it will work or not.

So, Please provide some light on this issue ASAP, I am waiting for your valuable feedbacks.


Thanks & Regard,

Umesh Sinha
u_sinha900@yahoo.com
India.

Hi,

few thoughts related with exception;

1) This exception occur when we are trying to access the properties/method of a Null object (not yet instantiated. having declaration only). for example,

SQLCommand cmd =null;
cmd.ExecuteNonQuery();

the above will throw the exception as you mentioned. So please check the objects declaration and related portions in the code.

2) Using OLEDBClient you can connect both SQL Server and Access easily.

Keep posted the results.

Good luck.

Thank you.

I'm afraid your session has expired. :)

1.check the connection string property.
2.check the objectconnection is open before executing the query for reading the data
from database.
3.check whether objected command is initialized using new key word as Mr.samphath suggested in the previous thread .


This is the coding in my sql just go through it this will return only one single value if you want to read a table or n number of tables use sqladapter with dataset

MySqlConnection objSourceCon = new MySqlConnection("ConfigurationManager.ConnectionStrings["myHRConnection"].Connection
String");
        MySqlCommand objSourceCmd = null;
        objSourceCmd = new MySqlCommand("Select * from tablename");
        objSourceCmd.Connection = objSourceCon;
        objSourceCon.Open();
        string str = objSourceCmd.ExecuteScalar().ToString();
        objSourceCon.Close();

pls post your code in which you are storing data in session var and after that you will get an error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.