Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Dear friends,
i am getting the following error:
Value cannot be null.
Parameter name: dataTable


on following Code Line,
C#
(adpTotalQuantity.Fill(dsTotalQuantity.Tables["Req_TotalInventoryRequired"]);


from here it goes into the Exceptions....wht could be issue with it?

my code is as below
C#
SqlCommand cmdTotalQuantity = new SqlCommand("GetRequestedInventoryDetls", conTotalQuantity);
                cmdTotalQuantity.CommandType = CommandType.StoredProcedure;
                cmdTotalQuantity.Connection = conTotalQuantity;

                cmdTotalQuantity.Parameters.Add("@RequestNo", SqlDbType.Int);
                cmdTotalQuantity.Parameters["@RequestNo"].Value = Convert.ToInt32(RequestNo);

                SqlDataAdapter adpTotalQuantity = new SqlDataAdapter(cmdTotalQuantity);
                DataSet dsTotalQuantity = new DataSet();

                adpTotalQuantity.Fill(dsTotalQuantity.Tables["Req_TotalInventoryRequired"]);

pl reply,
aamir
Posted
Updated 1-Jul-12 18:21pm
v2

Use the following line :
C#
adpTotalQuantity.Fill(dsTotalQuantity);
 
Share this answer
 
dsTotalQuantity.Tables["Req_TotalInventoryRequired"] is producing a null value. Try dsTotalQuantity.Tables[0] or whatever the index is.
 
Share this answer
 
Hi,
Try this:

C#
DataSet dsTotalQuantity = new DataSet();
DataTable dtReq=new DataTable();
adpTotalQuantity.Fill(dtReq);
dtReq.Name = "Req_TotalInventoryRequired";
dsTotalQuantity.Tables.Add(dtReq);


All the best.
--Amit
 
Share this answer
 
Comments
aamir07 2-Jul-12 0:47am    
Dear Amit,
i have used ur code but it gives me the error :object reference not set to an instance of an object

the error is in for loop:
for (int j = 0; j <= dsTotalQuantity.Tables["Req_TotalInventoryRequired"].Rows.Count; j++)
{
MaterialDescpt += ds.Tables["Req_TotalInventoryRequired"].Rows[j]["MaterialDesc"].ToString();
TotalUnitsRequired += ds.Tables["Req_TotalInventoryRequired"].Rows[j]["TotalUnitsRequired"].ToString();
}
_Amy 2-Jul-12 0:53am    
This error is coming just because your data-table is NULL.
Try putting a break-point and check the flow of data. whether it is coming in your data-set or not. Because whatever i gave you that is best from my knowledge. There is something which you are missing in-between.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900