Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
hi here is my sp
ALTER PROCEDURE [dbo].[usp_InsertBidTree1] 	
@DID varchar(20) output,
@DocType varchar(4) output,
@NodeID int,
@ParentNodeID int,
@Name varchar(50),
@Details varchar(max),
@Type varchar(50)  

AS BEGIN 
Insert into tblBidTree(btDID,btDocType,btName,btNodeID,btDetails,btParentNodeID,btType)
values(@DID,@DocType,@NodeID,@ParentNodeID,@Name,@Details,@Type)


END 


and in BLL
C#
public void InsertBidTree(TenderPreparationPL tprPL,SqlTransaction trans,SqlConnection cnn)
    {
        TenderPreparationDAL tprDAL = new TenderPreparationDAL();
        tprDAL.InsertBidTree(tprPL);
    }



DAL
SqlCommand cmd = new SqlCommand();
           SqlConnection con = new SqlConnection("Data Source=accerlap2;Initial Catalog=Tendering2;User ID=sa;Password=p@ssword;");
           con.Open();
           //cmd.Connection = cnn;
           //cmd.Transaction = trans;
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.CommandText = "usp_InsertBidTree1";
           cmd.Connection = con;

           SqlParameter paraDID = new SqlParameter("@DID", SqlDbType.VarChar, 20);
           SqlParameter paraDocType = new SqlParameter("@DocType", SqlDbType.VarChar, 4);
           SqlParameter paraNodeID = new SqlParameter("@NodeID", SqlDbType.Int);
           SqlParameter paraName = new SqlParameter("@Name", SqlDbType.VarChar, 50);
           SqlParameter paraParentNodeID = new SqlParameter("@ParentNodeID", SqlDbType.Int);
           SqlParameter paraType = new SqlParameter("@Type", SqlDbType.VarChar, 50);
           SqlParameter paraDetals = new SqlParameter("@Details", SqlDbType.VarChar, 1000);

           paraDID.Direction = ParameterDirection.Output;
           //paraDID.Value = objTPRPro.btDID;
           paraDocType.Direction = ParameterDirection.Output;
           //paraDocType.Value = objTPRPro.btDocType;
           paraNodeID.Value = objTPRPro.btNodeID;
           paraName.Value = objTPRPro.btName;
           paraParentNodeID.Value = objTPRPro.btParentNodeID;
           paraType.Value = objTPRPro.btType;
           paraDetals.Value = objTPRPro.btDetails;

           cmd.Parameters.Add(paraDID);
           cmd.Parameters.Add(paraDocType);
           cmd.Parameters.Add(paraNodeID);
           cmd.Parameters.Add(paraName);
           cmd.Parameters.Add(paraParentNodeID);
           cmd.Parameters.Add(paraType);
           cmd.Parameters.Add(paraDetals);

           cmd.ExecuteNonQuery();//here is da error  like usp_InsertBidTree1 @ParentNodeID which was not supply..
           objTPRPro.btDocType = paraDocType.Value.ToString();
           objTPRPro.btDID = paraDID.Value.ToString();


           con.Close();


in Save button click

 public bool Save(bool IsEmail)
    {

        BidTreePL objBIDPL = new BidTreePL();
        TenderPreparationPL objTPRPL1 = new TenderPreparationPL();
        //SqlTransaction trans;
        SqlConnection cnn = new SqlConnection();
        objBIDPL.btDID = SessionManager.TPR1DID;
        objBIDPL.btDocType = SessionManager.CurrentDocType;
       // objTPRPL.btDocType = objTPRPL.btDocType;
        objBIDPL.btName = objBIDPL.btName;//for btName and other controls i want to call from data table
        objBIDPL.btNodeID = objBIDPL.btNodeID;
        objBIDPL.btParentNodeID = objBIDPL.btParentNodeID;
        objBIDPL.btType = objBIDPL.btType;
        objBIDPL.btDetails = objBIDPL.btDetails;
        TenderPreparationDAL objTPRBL = new TenderPreparationDAL();
        objTPRBL.InsertBidTree(objTPRPL1);

}

in my web application am using controls as dynamic and code as static
now am getting error like usp_InsertBidTree1 @ParentNodeID which was not supply..

can any one suggest me how to solve this..
thanks
Posted
Updated 13-Jun-12 23:09pm
v2
Comments
Sandeep Mewara 14-Jun-12 5:14am    
Just looking at what you have shared, the code looks fine to me and should not give the error as you get. :(
ythisbug 14-Jun-12 6:50am    
now am getting error for @Name..actually i don know how to place in loop if there more than 3 records for same name..can u suggest me?
ythisbug 14-Jun-12 6:52am    
am using tree nodes so if i add more than three nodes tat name should be added can u suggest me how to do this?
db7uk 14-Jun-12 7:11am    
Please could you "Improve Question". I am confused as to what is actually happening now as there are several answers and several questions all on several threads... Please re-post the code you actually are working now rather than something from another time to help us determine if or where the problem is???
ythisbug 14-Jun-12 7:35am    
i posted another question.please check

Your sql insert does not look right.

SQL
Insert into tblBidTree(btDID,btDocType,btName,btNodeID,btDetails,btParentNodeID,btType)
values(@DID,@DocType,@NodeID,@ParentNodeID,@Name,@Details,@Type)


Your parameters are not correct for the insert values. i.e. the column btParentNodeID is being passed @Details.
 
Share this answer
 
Comments
Vani Kulkarni 14-Jun-12 6:01am    
Missed this. My 5!
ythisbug 14-Jun-12 6:12am    
ya ur rite.bt i modified after posting artical
Vani Kulkarni 14-Jun-12 6:13am    
So is your code working now?
ythisbug 14-Jun-12 6:39am    
no dear
ythisbug 14-Jun-12 6:16am    
but also same error for ParentNodeID
Your code is seems perfect, just make sure two things Parameter name is correct and it is case sensitive.

Also check at any point you are throwing exception but not handling in Catch, why I am asking because there might be a case where your exception is not handled and executing rest of statements.

Thank You
Rushikesh Joshi
 
Share this answer
 
Comments
ythisbug 14-Jun-12 5:14am    
thanks joshi
You will need to pass the parameters in the same order with that of the stored procedure. See your code below

C#
SqlParameter paraDID = new SqlParameter("@DID", SqlDbType.VarChar, 20);
SqlParameter paraDocType = new SqlParameter("@DocType", SqlDbType.VarChar, 4);
SqlParameter paraNodeID = new SqlParameter("@NodeID", SqlDbType.Int);
SqlParameter paraName = new SqlParameter("@Name", SqlDbType.VarChar, 50);
SqlParameter paraParentNodeID = new SqlParameter("@ParentNodeID", SqlDbType.Int);
SqlParameter paraType = new SqlParameter("@Type", SqlDbType.VarChar, 50);
SqlParameter paraDetals = new SqlParameter("@Details", SqlDbType.VarChar, 1000);


C#
cmd.Parameters.Add(paraDID);
cmd.Parameters.Add(paraDocType);
cmd.Parameters.Add(paraNodeID);
cmd.Parameters.Add(paraName);
cmd.Parameters.Add(paraParentNodeID);
cmd.Parameters.Add(paraType);
cmd.Parameters.Add(paraDetals);



You are passing the @Name parameter first, then the @ParentNodeID, where as in the stored procedure it is vice versa.
Either you change the order in stored procedure or in the code of DAL.
 
Share this answer
 
Comments
Sandeep Mewara 14-Jun-12 5:21am    
Interesting! Would like to know if this works.
As far as I knew, order was not important.
bbirajdar 14-Jun-12 5:26am    
Oh.. I need to remember this too... In case I get lost in a issue like this.. Given +5 ..but will take it back if the answer is not accepted
ythisbug 14-Jun-12 5:34am    
thanks but error is da same..
Sandeep Mewara 14-Jun-12 7:54am    
I thought so!

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