簡體   English   中英

使用C#或字符串處理圖像標簽處理SQLite數據

[英]Manipulating SQLite Data in C# or String Manipulation for Image Tag

我正在從事一個涉及SQLite數據庫和一堆圖像的項目。 一切都將放入外部硬盤驅動器,並且一切都是只讀的(沒有CRUD內容)。

該數據庫包含用於照片的表,其中一列(名為Path)是照片的路徑(字符串)。 我想使用Telerik旋轉器顯示這些照片(在RadWindow內,如果對您有幫助,可以在RadGrid中選擇一行后打開)。

我的問題是:路徑需要更改。 每個都以H:\\開頭,我需要將其刪除,然后替換為〜/ ThisFolder /(僅指向../ThisFolder)。 對於項目的其他每個部分,都可以使用ResolveUrl("~/ThisFolder/" + path.Remove(0, 3)) ,但我無法在此處弄清楚該如何做。

在將SQLite數據放入DataTable之后,我需要處理Path列中的數據,或者稍后再將Path字符串放入asp:Image標記之前進行操作。

這是我從SQLite數據庫中獲取數據並將其放入DataTable中的方法:

    public static DataTable dtTable;
    public static string connectionString = ConfigurationManager.ConnectionStrings["Entity"].ConnectionString;
    public SQLiteConnection SQLiteConnection = new SQLiteConnection(connectionString);
    public SQLiteDataAdapter SQLiteDataAdapter = new SQLiteDataAdapter();
    public SQLiteCommand SQLiteCommand = new SQLiteCommand();    

private void GetDataSource() //called in Page_Load
    {
        dtTable = new DataTable();
        SQLiteConnection.Open();
        try
        {
            string selectQuery = "SELECT ParentTableID, PhotoID, Path FROM tblPhoto";
            SQLiteCommand myCommand = new SQLiteCommand(selectQuery, SQLiteConnection);
            using (SQLiteDataReader myReader = myCommand.ExecuteReader())
            {
                dtTable.Load(myReader);
            }
            RadRotator1.DataSource = dtTable;
        }
        finally
        {
            SQLiteConnection.Close();
        }
        RadRotator1.DataBind();
    }

到目前為止,這是我的asp標簽:

<asp:Image ID="Images" runat="server" AlternateText="Images" ImageUrl='<%#Bind("~/ThisFolder/{0}", "Path")%>' />

雖然ImageURL是../ThisFolder/H:/yadayada。

任何幫助將非常感激! 如果我不清楚某個地方,請隨時提問。

我會嘗試使用SQLLite的replace

SELECT ParentTableID, PhotoID, replace(Path,'H:\\','') as Path FROM tblPhoto

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM