图片不显示在我的网站是从一个数据库驱动 [英] Images dont appear in my website that is driven from a database
问题描述
我正在使用Visual Studio的一个网站(C#ASP.Net)
并与数据库连接它,我利用了SQL服务器
I am making a website using visual studio (C# ASP.Net) and connecting it with a database I made use sql server
在我的数据库表我有一个名为图像列(w_image)
我用这种方式添加的图片链接到行 N'Image / 1.JPG
in my database table I have a column for image called (w_image)
I added image link to the rows using this way N'Image/1.jpg'
在网站code
我有这个code $是在网站页p $ PVIEW塔数据库表中的数据
in the website code I have this code that preview tha database table data in the website page
using System;
using System.Collections;
using System.Text;
public partial class Waqf : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FillPage();
}
private void FillPage()
{
ArrayList waqfList = ConnectionClass.GetWaqfByType(DropDownList1.SelectedValue);
StringBuilder sb = new StringBuilder();
foreach (Manu manu in waqfList)
{
sb.Append(string.Format(@"<table class='waqfTable'>
<tr>
<th rowspan='7' width='150px'><img runat='server' scr ='{7}' /></th>
<th width ='50px'>ID:</td>
<td>{0}</td>
</tr>
<tr>
<th>Type:</th>
<td>{1}</td>
</tr>
<tr>
<th>Shape:</th>
<td>{2}</td>
</tr>
<tr>
<th>Image Transcription: </th>
<td>{3}</td>
</tr>
<tr>
<th>Waqif Name: </th>
<td>{4}</td>
</tr>
<tr>
<th>Waqf place: </th>
<td>{5}</td>
</tr>
<tr>
<th>Waqf Date: </th>
<td>{6} A.H </td>
</tr>
</table>",
manu.w_id, manu.w_type, manu.w_shape, manu.w_imageTras, manu.waqif_name, manu.w_place, manu.w_date, manu.w_image));
lblOutput.Text = sb.ToString();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
FillPage();
}
}
这是连接类code
and this is the connection class code
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
public static class ConnectionClass
{
private static SqlConnection conn;
private static SqlCommand command;
static ConnectionClass()
{
string connectionString = ConfigurationManager.ConnectionStrings["manuConnection"].ToString();
conn = new SqlConnection(connectionString);
command = new SqlCommand("",conn);
}
public static ArrayList GetWaqfByType(string waqfType)
{
ArrayList list = new ArrayList();
string query = string.Format("SELECT * FROM waqf WHERE w_type LIKE '{0}' ", waqfType);
try
{
conn.Open();
command.CommandText = query;
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int w_id = reader.GetInt32(0);
string w_type = reader.GetString(1);
string w_shape = reader.GetString(2);
string w_imageTras = reader.GetString(3);
string waqif_name = reader.GetString(4);
string w_place = reader.GetString(5);
int w_date = reader.GetInt32(6);
string w_image = reader.GetString(7);
int m_id = reader.GetInt32(6);
Manu manu = new Manu(w_id, w_type, w_shape, w_imageTras, waqif_name, w_place, w_date, w_image, m_id);
list.Add(manu);
}
}
finally
{
conn.Close();
}
return list;
}
}
这是马努类code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class Manu
{
public int w_id { get; set; }
public string w_type { get; set; }
public string w_shape { get; set; }
public string w_imageTras { get; set; }
public string waqif_name { get; set; }
public string w_place { get; set; }
public int w_date { get; set; }
public string w_image { get; set; }
public int m_id { get; set; }
public Manu(int w_id, string w_type, string w_shape, string w_imageTras, string waqif_name, string w_place, int w_date, string w_image, int m_id)
{
this.w_id = w_id;
this.w_type = w_type;
this.w_shape = w_shape;
this.w_imageTras = w_imageTras;
this.waqif_name = waqif_name;
this.w_place = w_place;
this.w_date = w_date;
this.w_image = w_image;
this.m_id = m_id;
}
}
这是该项目,并为你看到的所有图像的图像文件夹区域提供
this is the project and as u see all the images ar available in the images folder
最后,这是最后的结果
所有的信息显示,除了图像
它想出现在左
finally this is the final result all the information appear except the image it suppose to appear in the left
我该怎么办,使图像出现?
what shall I do to make the images appear ?
推荐答案
也许只是在你的例子一个错字,但在这一行:
Maybe just a typo in your example but in this line:
<th rowspan='7' width='150px'><img runat='server' scr ='{7}' /></th>
SCRpresumably应该是SRC
'scr' presumably should be 'src'
这篇关于图片不显示在我的网站是从一个数据库驱动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!