Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
hi how to give code to place this code in loop while saving.
here is my code in btnSave click

BidTreePL objBIDPL = new BidTreePL();
        TenderPreparationPL objTPRPL1 = new TenderPreparationPL();
        //SqlTransaction trans;
        SqlConnection cnn = new SqlConnection();
        objTPRPL1.btDID = SessionManager.TPR1DID;
        objTPRPL1.btDocType = SessionManager.CurrentDocType;
       // objTPRPL.btDocType = objTPRPL1.btDocType;
        objTPRPL1.btName = objTPRPL1.btName;
        objTPRPL1.btNodeID = objTPRPL1.btNodeID;
        objTPRPL1.btParentNodeID = objTPRPL1.btParentNodeID;
        objTPRPL1.btType = objTPRPL1.btType;
        objTPRPL1.btDetails = objTPRPL1.btDetails;
        TenderPreparationDAL objTPRBL = new TenderPreparationDAL();
        objTPRBL.InsertBidTree(objTPRPL1);


here am getting error for @Name expects parameter..am using tree nodes and while adding more than three nodes i can change the name of that tree nodes and while saving it should save different records with tree node name.
and am using code as static and design as dynamic so am stuck with saving part..

for example
   objTPRPL1.btNodeID = objTPRPL1.btNodeID;
objTPRPL1.btNodeID=//how to set here like txtNodeID.Text(this we use for static) and how to use here for dynamic

and how to insert new rows (more than three records from tree node may be text box)into existing datatable using loop?
.so can any one suggest me
??
thanks u
Posted
Updated 14-Jun-12 18:51pm
v3

1 solution

The error message is related to a missing statement parameter. As your DAL is somewhere else, not in this piece of code, I can not guess the exact problem. But try to debug the InsertBidTree method, if you don't want to share it with us.
 
Share this answer
 
v2
Comments
ythisbug 15-Jun-12 0:35am    
this is InsertBidTree in Dal class
public void InsertBidTree(TenderPreparationPL objTPRPL1)
{

SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection("Data Source=accerlap2;Initial Catalog=Tendering2;User ID=sa;Password=p@ssword;");
con.Open();
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 paraParentNodeID = new SqlParameter("@ParentNodeID", SqlDbType.Int);
SqlParameter paraName = new SqlParameter("@Name", SqlDbType.VarChar, 50);
SqlParameter paraType = new SqlParameter("@Type", SqlDbType.VarChar, 50);
SqlParameter paraDetals = new SqlParameter("@Details", SqlDbType.VarChar, 1000);

paraDID.Direction = ParameterDirection.Output;

paraDocType.Value = objTPRPL1.btDocType;
paraNodeID.Value = objTPRPL1.btNodeID;
paraParentNodeID.Value = objTPRPL1.btParentNodeID;
paraName.Value = objTPRPL1.btName;
paraType.Value = objTPRPL1.btType;
paraDetals.Value = objTPRPL1.btDetails;

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

cmd.ExecuteNonQuery();

objTPRPL1.btDID = paraDID.Value.ToString();


con.Close();


}
Zoltán Zörgő 15-Jun-12 2:45am    
I really do not understand what you want. I assume you want to save the tree. Ok. You are saving for every change, or in a batch? I don't know what the stored procedure does, but as I see, this code is for a single node. You should not use the node name as key. Use some really unique ID.
Sorry, but these code snippets have no actual errors by themselves. You have some conceptual problems how you map your tree to db. It depends on the usage. If I were in your place I would store the tree in an XML field. As SQL server supports typed XML, you have really good support for that: http://msdn.microsoft.com/en-us/library/ms189887(v=sql.105).aspx but
There is nothing wrong in storing each node in a row either, but I can't see how objTPRPL1 is populated - you are passing all it's fields, but have you debugged, if all fields contain really valid data? And you should also consider how this node changes over time and if you have all information to alter the row mapped to it - or it is better to delete all rows related to that tree and recreate it.
ythisbug 15-Jun-12 4:57am    
objTPRPL1 is PL class..and changing in a batch..
Zoltán Zörgő 15-Jun-12 5:23am    
If changes in batch, how is it than that you pass only a single node to it?
Sorry, I can not read your mind. I can't debug, trace and think instead of you. A tree is a hierarchy, thus has to be consistent any time. As I see, you do not have means to keep all data representing the tree consistent. Rethink this from the scratch.
ythisbug 15-Jun-12 6:23am    
thanks zoltan..but i don knw how to save many nodes in single query..i gues by loop we can??

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