问题描述
我正在将文件上传到\ temp \,但是我想通过Access内部给定列中的超链接来访问它.我可以成功地将字符串粘贴到超链接字段,但是字符串和文件本身之间没有链接.
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.
我试图将粘贴的网站地址从浏览器复制到Access,令人惊讶的是,超链接与字符串"一起粘贴了
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();
}
我希望将字符串复制为超链接,但是,没有DbType假定这种数据类型吗?实际结果是:我可以成功将文件路径粘贴到该字段,但是该字段不包含指向任何内容的超链接:
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:
推荐答案
访问超链接类型字段所需要的值由3个部分组成,这些部分由#个字符分隔:displaytext#path#subreference
.选项:
Access Hyperlink type field requires value that is composed of 3 parts separated by # character: displaytext#path#subreference
. Options:
-
如果在Access表设计中使用超链接类型"字段,请在字符串中包含#个字符以进行保存.
If using Hyperlink type field in Access table design, include # characters in string to save.
只需使用文本字段保存不包含#个字符的路径字符串,然后在代码中使用FollowHyperlink方法或将字符串格式设置为带有连接表达式的超链接结构:"#" & [fieldname] & "#"
-在查询或文本框ControlSource中计算并将文本框IsHyperlink属性设置为是的.
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.
这篇关于将超链接值从C#粘贴到Access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!