Click here to Skip to main content
       

ASP.NET

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionerror in passing array parameter to a storedprocedurememberMember 870181316 Feb '13 - 16:28 
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<script type="text/javascript">
    function EnableUpload() {
        if (document.getElementById("<%=txtApplicationFormId.ClientID %>").value != "" && document.getElementById("<%=FileUpload1.ClientID %>").value != "" && document.getElementById("<%=FileUpload2.ClientID %>").value != "" && document.getElementById("<%=FileUpload3.ClientID %>").value != "") {
             document.getElementById("<%=btnSubmit.ClientID %>").disabled = false;
         }
         else {
             document.getElementById("<%=btnSubmit.ClientID %>").disabled = true;
         }
     }
 
    </script>
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
    <td align="left">
        &nbsp;</td>
    <td align="left" class="bgcolor" style="padding-left:10px">
        Application Id<asp:Label ID="Label1" runat="server" style="color: red;">*</asp:Label>
        </td>
    <td align="left" colspan="2">
        <asp:TextBox ID="txtApplicationFormId" runat="server"  MaxLength="20"  onChange = "javascript:EnableUpload();" ></asp:TextBox>
        <br />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  Display="Dynamic"
            ControlToValidate="txtApplicationFormId" ErrorMessage="ApplicationId&nbsp;is&nbsp;required" ForeColor="Red"
            SetFocusOnError="True" ValidationGroup="submit"></asp:RequiredFieldValidator>
        </td>
    </tr>
<tr>
    <td align="left">
        &nbsp;</td>
    <td align="left" class="bgcolor" style="padding-left:10px">
        Document1<asp:Label ID="Label2" runat="server" style="color: red;">*</asp:Label>
        </td>
    <td align="left"  colspan="2">
        <asp:FileUpload ID="FileUpload1" runat="server"  onChange = "javascript:EnableUpload();" ></asp:FileUpload>
        <br />
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Display="Dynamic"
            ControlToValidate="FileUpload1" ErrorMessage="Document1&nbsp;is&nbsp;required" ForeColor="Red"
            SetFocusOnError="True" ValidationGroup="submit"></asp:RequiredFieldValidator>
        </td>
    </tr>
<tr>
    <td align="left">
        &nbsp;</td>
    <td align="left" class="bgcolor" style="padding-left:10px" valign="top">
        Document2<asp:Label ID="Label3" runat="server" style="color: red;">*</asp:Label>
        </td>
    <td align="left"  colspan="2">
        <asp:FileUpload ID="FileUpload2" runat="server" onChange = "javascript:EnableUpload();" ></asp:FileUpload>
        <br />
             <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" Display="Dynamic"
            ControlToValidate="FileUpload2" ErrorMessage="Document2&nbsp;is&nbsp;required"
            ForeColor="Red" SetFocusOnError="True" ValidationGroup="submit"></asp:RequiredFieldValidator>
        </td>
    </tr>
<tr>
    <td align="left">
        &nbsp;</td>
    <td align="left" class="bgcolor" style="padding-left:10px" valign="top">
        Document3<asp:Label ID="Label4" runat="server" style="color: red;">*</asp:Label>
        </td>
    <td align="left"  colspan="2">
        <asp:FileUpload ID="FileUpload3" runat="server"  onChange = "javascript:EnableUpload();" ></asp:FileUpload>
        <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" Display="Dynamic"
            ControlToValidate="FileUpload3" ErrorMessage="Document3&nbsp;is&nbsp;required"
            ForeColor="Red" SetFocusOnError="True" ValidationGroup="submit"></asp:RequiredFieldValidator>
        </td>
    </tr>
<tr>
    <td align="left">
        &nbsp;</td>
    <td align="left" class="bgcolor" style="padding-left:10px">
        Description
        </td>
    <td align="left"  colspan="2">
        <asp:TextBox ID="txtdescription" runat="server" TextMode="MultiLine" Width="58%"></asp:TextBox>
        </td>
    </tr>
<tr>
 <td align="center" colspan="4">
        <asp:Button ID="btnSubmit" runat="server" Text="Submit"
            ValidationGroup="submit" onclick="btnSubmit_Click" Enabled="False"/>
</table>
</td>
 </tr>
</ContentTemplate>
<Triggers>
 
<asp:PostBackTrigger ControlID="btnSubmit" />
 
</Triggers>
 
    </asp:UpdatePanel>
on codebehind file:
protected void btnSubmit_Click(object sender, EventArgs e)
        {
 

            try
 
            {
 HttpFileCollection hfc = Request.Files;
                fn = new string[hfc.Count];
docloc = new string[hfc.Count];
                for (int i = 0; i < hfc.Count; i++)
                {
 
                    HttpPostedFile hpf = hfc[i];
 
                    if (hpf.ContentLength > 0)
                    {
                        fn[i] = Path.GetFileName(hpf.FileName);
                        docloc[i] = Path.GetFullPath(hpf.FileName);
                        hpf.SaveAs(@"D:\testfiles\" + fn[i]);
}
                }
                int j = conn.insert_update_request("Insert", 6, Convert.ToString(docloc[0]),Convert.ToString(docloc[1]),Convert.ToString(docloc[2]), txtdescription.Text.ToString(), 1, txtApplicationFormId.Text.ToString());
            }
 
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
}
public int insert_update_request(string type, int usertypeid, string doc1location, string doc2location, string doc3location, string description, int statusid, string applicationid)
        {
            int i;
            try
            {
                connection.Open();
                    SqlCommand cmd = new SqlCommand("sp_insert_update_request", connection);
                    cmd.Connection = connection;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@type", type);
                    cmd.Parameters.AddWithValue("@UserTypeId", usertypeid);
                    cmd.Parameters.AddWithValue("@Document1location", doc1location);
                    cmd.Parameters.AddWithValue("@Document2location", doc2location);
                    cmd.Parameters.AddWithValue("@Document3location", doc3location);
                    cmd.Parameters.AddWithValue("@descr", description);
                    cmd.Parameters.AddWithValue("@StatusId", statusid);
                    cmd.Parameters.AddWithValue("@ApplicationId", applicationid);
                    i = cmd.ExecuteNonQuery();
            }
            catch(Exception ex)
            {
                i = 0;
                Console.WriteLine(ex.Message);
            }
            finally
            {
                connection.Close();
            }
            return i;
        }
ALTER procedure [dbo].[sp_insert_update_request] 
(@type varchar(20),
@applicationid nvarchar(max),
@usertypeid int,
@doc1location nvarchar(max),
@doc2location nvarchar(max),
@doc3location nvarchar(max),
@description nvarchar(max),
@statusid int)
as
begin 
      if(@type = 'Insert')
      begin
         insert into Request(UserTypeId,Document1location,Document2location,Document3location,descr,StatusId,ApplicationId )
            values
            (@usertypeid,@doc1location,@doc2location,@doc3location,@description,@statusid,@applicationid)
      end
 
end
i am getting the following error....
Procedure or function 'sp_insert_update_request' expects parameter '@doc1location', which was not supplied.
pls suggest me ....how to solve this issue...i am struggling for the past 4 days....
AnswerRe: error in passing array parameter to a storedproceduremvpSandeep Mewara16 Feb '13 - 18:18 
Member 8701813 wrote:
cmd.Parameters.AddWithValue("@Document1location", doc1location);
cmd.Parameters.AddWithValue("@Document2location", doc2location);
cmd.Parameters.AddWithValue("@Document3location", doc3location);

 
Member 8701813 wrote:
@doc1location nvarchar(max),
@doc2location nvarchar(max),
@doc3location nvarchar(max),

Do you see the mismatch in the names of the parameter?
 
SP is expecting a parameter name '@doc1location' where as you are passing '@Document1location' from your code. (same error will be raised for doc2 & doc3).
 
Make sure the parameter name expected/defined in SP is exactly the same as you pass from your code behind.
Sandeep Mewara
Microsoft ASP.NET MVP 2012 & 2013

[My Blog]: Sandeep Mewara's Tech Journal!
[My Latest Article]: HTML5 Quick Start Web Application

GeneralRe: error in passing array parameter to a storedprocedurememberMember 870181316 Feb '13 - 20:45 
thanks a lot.its working.i am new to asp.net & sql server

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid