这是响应question我刚才问,因为我不能8小时前有后,我已经创建了一个新的问题,与我所面临的问题,问题与SqlDataReader!
下面的代码:
if (context.Request.QueryString["id"] != null)
{
int id = int.Parse(context.Request.QueryString["id"].ToString());
string connectionString = "Data Source=tarun-PC\\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True";
string commandString = "Select fsImage from WHATSNSTORE_FEATURED_STORES where imageId=" + id;
SqlConnection oConnection = new SqlConnection(connectionString);
SqlCommand oCommand = new SqlCommand(commandString, oConnection);
if (oConnection.State != ConnectionState.Open)
{
oConnection.Open();
}
SqlDataReader myDataReader = oCommand.ExecuteReader();
//myDataReader.Read();
try
{
if (myDataReader.Read())
{
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite((byte[])myDataReader["fsImage"]);
}
}
catch (Exception ex)
{
context.Response.Write(ex.Message);
}
我的表
create table WHATSNSTORE_FEATURED_STORES
(
imageId int primary key identity,
fsImage image
)
只有现在的问题是,在调试时它跳过if(myDataReader.Read())
部分,这表明没有数据存在!
我该如何解决问题?
你有错误吗?在_context.Response.Write(ex.Message); _你有东西吗?在该行添加一个喙点并检查您的应用程序是否在那里登台... – Marco 2011-05-16 13:03:15
如果没有数据存在,那意味着您需要获取数据。 – Avitus 2011-05-16 13:04:02
@Marco没有if(),当我运行代码时,我得到的错误是“无效的尝试读取,当没有数据存在”..再次,我跑在SSMS查询,我获得理想的结果! – cSharpNovice 2011-05-16 13:23:47