Pasting a hyperlink value from C# to Access

你说的曾经没有我的故事 提交于 2020-01-24 00:24:47

问题


I am uploading a file to \temp\ but I want to access it through a hyperlink in a given column inside Access. I can successfully paste the string to the hyperlink field, but there´s no link between the string and the file itself.

I tried to copy paste a website address from a browser to Access, surprisingly the hyperlink is pasted along with the "string"

//upload arquivo
string conexaoAccess2 = ConfigurationManager.ConnectionStrings["conexaoAccess"].ToString();
using (OleDbConnection conexaodb1 = new OleDbConnection(conexaoAccess2))
{
    conexaodb1.Open();

    Random r = new Random();
    int n = r.Next();
    // pega somente nome 
    string[] f = camArq.Split('\\');
    string fn = f[(f.Length) - 1];
    string fullDest = @"C:\temp\" + nomeArqnoExt + n + fileExtension0;
    string q = "UPDATE tbl_reg SET Campo1 = @campo WHERE nome_user = @nome1";

    //copia arquivo para a pasta destino
    File.Copy(camArq, fullDest, true);

    //to save to the database
    OleDbCommand cmd = new OleDbCommand(q, conexaodb1);
    var parCamp = cmd.CreateParameter();
    parCamp.ParameterName = "campo";
    parCamp.DbType = DbType.String;
    parCamp.Value = fullDest;
    cmd.Parameters.Add(parCamp);

    var parNome1 = cmd.CreateParameter();
    parNome1.ParameterName = "nome1";
    parNome1.DbType = DbType.String;
    parNome1.Value = mdl.nome;
    cmd.Parameters.Add(parNome1);

    cmd.ExecuteNonQuery();
}

I expect the string to be copied as an hyperlink, nevertheless, there´s no DbType that assumes this type of data, is there? The actual results are: I can successfully paste the file path to the field, but the field contains no hyperlink to anything whatsoever:


回答1:


Access Hyperlink type field requires value that is composed of 3 parts separated by # character: displaytext#path#subreference. Options:

  1. If using Hyperlink type field in Access table design, include # characters in string to save.

  2. Just use a text field to save path string without # characters then use FollowHyperlink method in code or format string to hyperlink structure with concatenation expression: "#" & [fieldname] & "#" - calculate in query or textbox ControlSource and set textbox IsHyperlink property to yes.



来源:https://stackoverflow.com/questions/58766581/pasting-a-hyperlink-value-from-c-sharp-to-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!