We help IT Professionals succeed at work.
Get Started

expects the parameter which was not supplied error

ocdc
ocdc asked
on
858 Views
Last Modified: 2013-11-26
Certain browsers (Chrome 5, Safari 4) produce an error when a file is not uploaded or no data is provided.

Error is:
The parameterized query '(@FileId int,@RUFileName nvarchar(100),@RUFileType nvarc' expects the parameter '@RefLetterType', which was not supplied.


Source Error:

Line 119:            command.Parameters.Add("@CLContent", SqlDbType.VarBinary).Value = fileCLContent;
Line 120:            command.Connection.Open();
Line 121:            command.ExecuteNonQuery();
Line 122:
Line 123:        }

Source File: c:\web\HR\OApp\App\Files.aspx.cs    Line: 121
using (SqlCommand command = new SqlCommand())
        {
            command.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["JConnectionString1"].ConnectionString);
            command.CommandText = @"insert into [appfiles](FileId, RUFileName, RUFileType, RUFileSize, CLName, CLType, CFSize, RefLetterName, RefLetterType,RefLetterSize, ResText, ReferenceLetterText,CoverLetterText,ResContent,CoverLetterContent,RefContent)
            						values(@FileId, @RUFileName, @RUFileType, @RUFileSize, @CLName, @CLType,@CFSize,@RefLetterName,@RefLetterType,@RefLetterSize, @ResText, @ReferenceLetterText,@CoverLetterText,@ResContent,@CLContent,@RefContent)";

            command.Parameters.Add("@FileId", SqlDbType.Int).Value = int.Parse(Session["FileId"].ToString());
			
            command.Parameters.Add("@RUFileName", SqlDbType.NVarChar, 100).Value = Path.GetFileName(fuRes.PostedFile.FileName);
            command.Parameters.Add("@RUFileType", SqlDbType.NVarChar, 100).Value = fuRes.PostedFile.ContentType;
            command.Parameters.Add("@RUFileSize", SqlDbType.Int).Value = fuRes.PostedFile.ContentLength;

            command.Parameters.Add("@CLName", SqlDbType.NVarChar, 100).Value = Path.GetFileName(fuCLetter.PostedFile.FileName);
            command.Parameters.Add("@CLType", SqlDbType.NVarChar, 100).Value = fuCLetter.PostedFile.ContentType;
            command.Parameters.Add("@CFSize", SqlDbType.Int).Value = fuCLetter.PostedFile.ContentLength;
            

            command.Parameters.Add("@RefLetterName", SqlDbType.NVarChar, 100).Value = Path.GetFileName(fuRefLetter.PostedFile.FileName);
            command.Parameters.Add("@RefLetterType", SqlDbType.NVarChar, 100).Value = fuRefLetter.PostedFile.ContentType;
            command.Parameters.Add("@RefLetterSize", SqlDbType.Int).Value = fuRefLetter.PostedFile.ContentLength;

            
            // filecontent, convert from stream to byte array
            byte[] fileResContent = new byte[fuRefLetter.PostedFile.ContentLength];
            
            //fuRefLetter.PostedFile.InputStream.Read(fileResContent, 0, fuRefLetter.PostedFile.ContentLength);
            Stream File1Stream;
            File1Stream = fuRefLetter.PostedFile.InputStream;  
            File1Stream.Read(fileResContent, 0, fuRefLetter.PostedFile.ContentLength);  
            command.Parameters.Add("@RefContent", SqlDbType.VarBinary).Value = fileResContent;

            byte[] fileResContent = new byte[fuRes.PostedFile.ContentLength];
            fuRes.PostedFile.InputStream.Read(fileResContent, 0, fuRes.PostedFile.ContentLength);
            command.Parameters.Add("@ResContent", SqlDbType.VarBinary).Value = fileResContent;

            byte[] fileCLContent = new byte[fuCLetter.PostedFile.ContentLength];
            fuCLetter.PostedFile.InputStream.Read(fileCLContent, 0, fuCLetter.PostedFile.ContentLength);
            command.Parameters.Add("@CLContent", SqlDbType.VarBinary).Value = fileCLContent;
            command.Connection.Open(); 
            command.ExecuteNonQuery();

        }

Open in new window

Comment
Watch Question
C# ASP.NET Developer
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE