Note that there are some explanatory texts on larger screens.

plurals
  1. POSolve Error: Object reference not set to an instance of an object
    primarykey
    data
    text
    <p>I am getting this eror while uploading a Image file using FileUpload. I am getting this error on button click event to insertion</p> <pre><code> public int InsertData(ProductPhoto prdctphoto) { int ans = 0; SqlCommand cmd = DataConnection.GetConnection().CreateCommand(); cmd.CommandText = "prcProductPhoto"; cmd.CommandType = CommandType.StoredProcedure; // cmd.Parameters.Add(new SqlParameter("@PhotoID", prdctphoto.PhotoID)); cmd.Parameters.Add(new SqlParameter("@PhotoName", prdctphoto.PhotoName)); cmd.Parameters.Add(new SqlParameter("@ExtName", prdctphoto.ExtName)); cmd.Parameters.Add(new SqlParameter("@PhotoType", prdctphoto.PhotoType)); cmd.Parameters.Add(new SqlParameter("@PhotoSize", prdctphoto.PhotoSize)); cmd.Parameters.Add(new SqlParameter("@ProductID", prdctphoto.ProductID)); ans = int.Parse(cmd.ExecuteScalar().ToString()); cmd.Dispose(); DataConnection.CloseConnection(); return ans; } </code></pre> <p>i am getting the error in line </p> <p>ans = int.Parse(cmd.ExecuteScalar().ToString());</p> <p>The code of my Stored Procedure is </p> <pre><code>create proc prcProductPhoto ( @PhotoName Varchar(100), @ExtName Varchar(100), @PhotoType Varchar(100), @PhotoSize int, @ProductID Int ) as insert into ProductPhoto(PhotoName,ExtName,PhotoType,PhotoSize,ProductID) values (@PhotoName,@ExtName,@PhotoType,@PhotoSize,@ProductID) </code></pre> <p>and code on button click event is </p> <pre><code>protected void Insert_Click(object sender, EventArgs e) { try { if (photoupload.HasFile) { ProductPhoto prdctphoto = new ProductPhoto(); prdctphoto.PhotoName = photoupload.FileName; prdctphoto.PhotoSize = photoupload.PostedFile.ContentLength; prdctphoto.PhotoType = photoupload.PostedFile.ContentType; prdctphoto.ExtName = prdctphoto.PhotoName.Substring(prdctphoto.PhotoName.LastIndexOf(".") + 1); prdctphoto.ProductID = int.Parse(ddlproductname.SelectedValue); //Response.Write(data.ExtName); int ans = new InsertAction().InsertData(prdctphoto); if (ans != 0) { string path = Server.MapPath("~/upload/") + ans.ToString() + "." + prdctphoto.ExtName; photoupload.SaveAs(path); Response.Write(" File is Uploaded "); } } } catch (Exception ex) { Response.Write(ex.Message); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload