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); _ 뭔가 있습니까? 해당 라인에 beakpoint를 놓고 앱이 거기에 발걸음을 내딛었는지 확인하십시오 ... 데이터가 필요하다는 것을 의미하는 데이터가 없다면 – Marco
을 입력하십시오. – Avitus
@Marco가 if()없이 코드를 실행할 때 "잘못된 데이터가 없을 때 읽으려는 시도"입니다. 다시 SSMS에서 쿼리를 실행했습니다. 원하는 결과를 얻는 중! – cSharpNovice