how to pass data from many fields to a stored procedure RRS feed

  • Question

  • hi,

    i have to pass data entered by the user from 14 fields to a stored procedure and those fields are of different data types. how i should pass it and store the data entered by the user in a database.


    i am using 3-tire architechture (presentation layer- business layer- data layer)


    i tried get some ways to send datarow to stored proceduce but could find a good result.


    Can anyone suggest me how should i do this.





    Tuesday, October 16, 2007 1:11 PM

All replies

  • Hi,


    Is there a reason why you do not want to use a collection of parameters to pass the 14 data items to your Stored Procedure?


    Conceptually, I guess you could pack the 14 items into a string (maybe xml based or delimitted)  and pass it as a single parameter to your procedure and unpack it there.

    Tuesday, October 16, 2007 6:01 PM
  • Hey Johny,

    If sending 14 fields is the only way then you can try something like the following:

    Code Snippet
    //In the Business Layer

    DataBaseMgr dbMgr = new DataBaseMgr();

    dbMgr.Insert(field0, ......., field13);

    //In the Data layer

    public class DataBaseMgr

    public void Insert(DataType field0, ......., DataType field13)
    //Assuming Sql Server Database

    SqlConnection sqlConn = new SqlConnection(connString);

    SqlCommand sqlCmd = new SqlCommand(sqlConn);
    sqlCmd.CommandType = CommandType.StoredProcedure;
    sqlCmd.CommandText = "spStoredProcedureName";

    sqlCmd.Parameters.AddWithValue("@Param0", field0);// Make sure that Param0 and so on are the actual names of the parameter in your stored procedure
    sqlCmd.Parameters.AddWithValue("@Param13", field13);



    Hope this helps you,

    Tuesday, October 16, 2007 9:04 PM