图像不会出现在我的网站中,该网站是从数据库驱动的

时间:2014-05-02 16:38:27

标签: c# asp.net sql image visual-studio

我正在使用visual studio制作网站(C#ASP.Net) 并将其与我使用的数据库连接使用sql server

在我的数据库表中我有一个名为(w_image)的图像列 我使用这种方式N'Image/1.jpg'

添加了行的图像链接

table

在网站代码中 我有这个代码在网站页面中预览数据库表数据

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();
    }
}

这是连接类代码

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;
    }
}

这是manu类代码

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;

    }
}

这是项目,你可以看到图像文件夹中的所有图像

visual studio project

最后这是最终的结果 除图像外,所有信息均显示 它假设出现在左侧

我该怎样做才能让图像出现?

website

1 个答案:

答案 0 :(得分:2)

在你的例子中可能只是一个拼写错误,但在这一行:

 <th rowspan='7' width='150px'><img runat='server' scr ='{7}' /></th>

&#39; SCR&#39;大概应该是&#39; src&#39;