'System.Data.SqlClient.SqlDataReader' has no constructors defined, Please check the code I can't fixed this problem
When I am run this code I am faceing thisproblem in SqlDataReader dr = new SqlDataReader(); The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined, Please check the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace PhotoGellaryy.Models
{
public class PhotoGellary
{
public string strcn =
ConfigurationManager.ConnectionStrings["UploadImagesEntities"].ToString();
public IList<UploadImagesViewModel>GetImages()
{
SqlConnection con = new SqlConnection(strcn);
List<UploadImagesViewModel> photogellary = new
List<UploadImagesViewModel>();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select ImageID,ImageName from
ImageUploadTbl";
con.Open();
SqlDataReader dr = new SqlDataReader();
while(dr.Read())
{
UploadImagesViewModel objuploadimagesviewmodel = new
UploadImagesViewModel();
//objuploadimagesviewmodel.ImageID =
dr["ImageID"].ToString();
objuploadimagesviewmodel.ImageName =
dr["ImageName"].ToString();
photogellary.Add(objuploadimagesviewmodel);
}
if(dr!= null)
{
dr.Dispose();
dr.Close();
}
con.Close();
return photogellary.ToList();
}
}
}
}
SqlDataReader: "To create aSqlDataReader, you must call theExecuteReadermethod of theSqlCommandobject, instead of directly using a constructor."SqlConnection,SqlCommandandSqlDataReaderare allIDisposableand should each be inusingblocks, then you won't need either of theCloses or theDisposebecause the implicit Dispose will handle that for you.