问题描述
嗨...
我正在尝试使用C#将文件地址保存在SQL Server数据库中,但我不知道我需要在数据库中使用什么数据类型",或者我是否需要一些我不需要的代码不知道...
就像这样:我创建了一个数据库,并创建了一个带有列的表,其中定义了nvarchar(100)类型,并用地址c:\ projects \ vids \ simpsonslidetector.flv填充",但是当我尝试时要从该列获取结果,我只能检索simpsonslidetector,并且我想检索包括文件扩展名的整个路径...
也有一种写绝对地址的方法,例如:机器地址" \ vids \ simpsonslidetector.flv
所以我不能在任何计算机上使用它?
谢谢人们
Hi...
I''m trying to get a file address saved on the SQL server database using c#, but i don''t know what ''data type'' i need to use in the database or if i need some code that i don''t know...
it''s like this: i have created a database and made a table with a column where i define a type nvarchar(100) and "fill it" with the address c:\projects\vids\simpsonslidetector.flv but when i try to get the result from that column i can only retrieve simpsonslidetector, and i want to retrieve the whole path including the file extension...
also is there a way of writing the absolute address, something like: "the machine address"\vids\simpsonslidetector.flv
so i cant use it on any computer???
thanks people
推荐答案
[WebMethod]
public String getAddressByID(Int32 id)
{
String strReader = "";
SqlConnection conn = new SqlConnection(strCon);
conn.Open();
String readCmd = "SELECT address FROM info WHERE id = " + id.ToString();
SqlCommand cmd = new SqlCommand(readCmd, conn);
strReader = (String)cmd.ExecuteScalar();
conn.Close();
if (strReader == null)
{
return "No Result";
}
else
{
return strReader;
}
}
PS:我等待回复时,将阅读OriginalGriff发布的 []文档(谢谢). .
P.S.: while i wait for a response i will read the [MSDN] document OriginalGriff posted (thanks)...
这篇关于SQL保存/加载文件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!