currently I am doing an online store project using an example from one of your tutorials. In the grid view is populated with data and at the below of the grid view, there is a row of empty fields populated below. After user have enter all the necessary info and clicks on the Add New link, the data will be inserted into the database and it will also be displayed in the grid view itself.
The software that I am using is called: MS VS 2008 C#
The database that I am using is called: MS SQL Server 2008
The attachment contains the database.cs, stored procedure and business logic. When I debug there is an error indicating:Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
This sentence is highlighted in red-osdb.Insert_ItemsRecords(txtID.Text, txtItemName.Text, txtItemDesc.Text);
BindGrid(true);
BindGrid(true);
Thanks
Suthish NairPosted Feb 7, 2011, 5:39 AM
Secondly how executeNonQuery works.
Third, put a breakpoint and check each line of code.
Becky BloomwoodPosted Feb 6, 2011, 12:21 PM
public void Insert_ItemsRecords(string id, string itemName, string itemDesc)
{
SqlCommand cmd_ItemsList = new SqlCommand();
cmd_ItemsList.CommandText = "[VRM].[INSERT_ItemsRecords]";
cmd_ItemsList.CommandType = CommandType.StoredProcedure;
cmd_ItemsList.Parameters.Clear();
SqlParameter sqlParaID = new SqlParameter("@id", SqlDbType.VarChar, 10);
sqlParaID.Value = id;
cmd_ItemsList.Parameters.Add(sqlParaID);
SqlParameter sqlParaItemName = new SqlParameter("@itemName", SqlDbType.VarChar, 100);
sqlParaItemName.Value = itemName;
cmd_ItemsList.Parameters.Add(sqlParaItemName);
SqlParameter sqlParaItemDesc = new SqlParameter("@itemDesc", SqlDbType.VarChar, 1000);
sqlParaItemDesc.Value = itemDesc;
cmd_ItemsList.Parameters.Add(sqlParaItemDesc);
return ;
}
But the error is still the same. How do I resolve it?
Thks!
Mahesh ChandPosted Feb 6, 2011, 11:49 AM
osdb is a class. Before you can use it, you must create an instance of it using "new" keyword. For example,
YourClassName osdb = new YourClassName ();
Replace YourClassName with the name of the class. Use a proper constructor.
Becky BloomwoodPosted Feb 6, 2011, 11:32 AM
Suthish NairPosted Feb 6, 2011, 11:23 AM
Insert_ItemsRecords returns bool.
Becky BloomwoodPosted Feb 6, 2011, 6:42 AM
Suthish NairPosted Feb 6, 2011, 6:15 AM
Becky BloomwoodPosted Feb 6, 2011, 6:10 AM
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
This sentence is highlighted in red:
osdb.Insert_ItemsRecords(txtID.Text, txtItemName.Text, txtItemDesc.Text);
BindGrid(true);
How do I set the osdb to a valid instance? Thanks
Suthish NairPosted Feb 6, 2011, 5:59 AM
Becky BloomwoodPosted Feb 6, 2011, 3:39 AM
BindGrid(true);