'System.Data.SqlClient.SqlDataReader'没有定义的构造函数, 请检查代码 我无法解决这个问题
当我运行这段代码时,我在SqlDataReader中遇到了这个问题dr = 新的SqlDataReader(); 类型'System.Data.SqlClient.SqlDataReader'没有构造函数 定义,请检查代码
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();
}
}
}
}
答案 0 :(得分:0)