當前位置:首頁 » 編程語言 » netsqlimage
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

netsqlimage

發布時間: 2022-04-21 04:00:30

❶ vb.net+mssql如何刪除image欄位里的圖片

沒大明白樓主的意思。
刪除一個表內一條數據?
刪除一個表內一條數據內的一個欄位,這個欄位是image類型的?
意思就是修改這條數據,僅僅是把這個image類型欄位內容清空?
直接讓這欄位=null把。

❷ sql資料庫image欄位設為varchar類型怎麼不對

image在資料庫中是以二進制存儲的,所以varchar肯定不行,存儲image一般使用blob吧,你嘗試一下,這個東西我也不記得了,包括音頻,視頻,圖片等等都是二進制數據

❸ asp.net image控制項如顯示資料庫對應圖片

//把從資料庫取出來的內容解析成二進制
byte[] bytes = (byte[])dataTable.Rows[0][ "Image"];
//再把二進制轉換成文件流
MemoryStream ms = new MemoryStream(bytes);
//把流文件輸出成img
Image img = Image.FromStream(ms);
----------------------------------------------------------以上是在網上找的,我也是這樣想的。
生成一個圖片在內存中,綁定到頁面顯示,頁面關閉的時候自動銷毀,不寫文件,以免生成垃圾文件……
咋綁一時想不起來,
還一種辦法就是用<img src="生成圖片地址.ASPX"/>這樣的方式來請求一個頁面,在那個頁面輸出從資料庫獲取的流文件轉換成的圖片再顯示。
這樣的話效率可能很差。
除非文件不是機密或防盜一般不要存資料庫。

❹ ADO.NET修改Sql Server資料庫中的image數據類型的欄位的值的C#代碼該怎麼樣編寫啊

你網路搜索一下
c#從資料庫中保存/獲取圖片
第一個就是

❺ ADO.NET修改Sql Server中的image數據類型的欄位的值的C#代碼該怎麼編寫啊

最好的方法是存圖片路徑到資料庫,然後同時把文件上傳到伺服器路徑下。次之的辦法是直接把圖片存到資料庫,辦法是先把圖片的bitmap二進制序列用base64加密,然後就變成了文本,就可以像普通字元串一樣存,讀的時候反過來。

❻ 有高手可以給我講解下asp.net讀取SQL裡面的image欄位顯示出圖片!

首先要確保你的路徑在資料庫中要正確,比如在你的項目中有一個Image文件夾,裡面放置的圖片,那麼在資料庫中就這樣寫~/Image/1.jpg,相對路徑,
然後在前台頁面顯示的時候就要進行綁定了,記得不要用lable控制項,如果用的話,讀取出來的就是原來的路徑,也就是:~/Image/1.jpg,所以在
image控制項
中綁定:eval("
欄位名
"),
代碼應該會寫吧!
差不多就這樣!

❼ 取資料庫image類型圖片的問題

圖片是二進制欄位數據(文件)

20.資料庫存入二進制欄位數據
/*
using System.Data;
using System.IO;
using System.Data.SqlClient;
*/
private string File="";
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
pictureBox1.Image=new Bitmap(openFileDialog1.FileName);
FileName=openFileDialog1.FileName;
}
try{
DataSet ds=new DataSet();
sqlDataAdapter1.Fill(ds,%%1); //"db"
DataTable MyTable=ds.Tables[0];
DataRow MyRow=MyTable.Rows.Count+1;
MyRow[%%2]=MyTable.NewRow(); //"id"
MyRow[%%3]=%%5; //"FileName"
MyRow[%%4]=%%6; //"Description"
FileStream fs=new FileStream(FileNmae,FileMode.OpenOrCreate,FileAccess.Read);
byte[] MyData=new byte[fs.Length];
fs.Read(MyData,0,(int)fs.Length);
MyRow[%%7[=MyData; //"FileData"
MyTable.Rows.Add(MyRow);
sqlDataAdapter1.Update(ds,%%1);
ds.AcceptChanges();
//存儲成功
}
catch(Exception ex)
{
//ex.Message.ToString()
}

21.資料庫取出二進制欄位數據
/*
using System.Data;
using System.IO;
*/
private int index=1;
private System.Windows.Forms.BindingManagerBase_Bind();
private DataSet ds=new DataSet();
sqlDataAdapter1.Fill(ds,%%1); //"db"
_Bind=BindingContext[ds,%%1];
textBox1.DataBindings.Add("Text",ds,"%%1.%%3"); //filename
textBox2.DataBindings.Add("Text",ds,"%%1.%%4"); //description
if(_Bind.Count!=0)
{
try{
if(pictureBox1.Image!=null)
pictureBox1.Image.Dispose();
pictureBox1.Image=null;
sqlDataAdapter1.SelectCommand.CommandText="Select * From %%1 Where %%2="+Convert.ToString(index); //id
DataSet dataSet=new DataSet();
sqlDataAdapter1.Fill(dataSet,%%1);
byte[] MyData=(byte[])dataSet.Tables[0].Rows[0][%%5]; //"FileData"
Int32 size=MyData.GetUpperBound(0);
FileStream fs=new FileStream(%%6,FileMode.OpenOrCreate,FileAccess.Wrtie); //"temp.bmp"
fs.Write(MyData,0,size+1);
fs.Close();
pictureBox1.Image=new Bitmap(%%6);
}
catch(Exception ex)
{
//ex.Message.ToString()
}
}

22.批量執行SQL和存儲過程
/// <summary>
/// 儲存過程->刪除;
/// </summary>
/// <param name="id"> </param>
/// <returns> </returns>
public DataTable GetTable(int id)
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection("server=.;database=master;User id=sa;pwd=sa");
SqlCommand com = new SqlCommand("proc_Shoping", con); //連接資料庫執行存儲過程
com.CommandType = CommandType.StoredProcere;
//執行存儲過程
SqlDataAdapter da = new SqlDataAdapter(com);
SqlParameter param; //添加一個輸入參數
param = new SqlParameter("@id", SqlDbType.Int); //設置類型為輸入類型 ,並傳入參數;
param.Direction = ParameterDirection.Input;
param .Value= id; //當前參數的值
param.Value =10;
com.Parameters.Add(param); //將設置好的sqlparameter對象添加到da中
da.Fill(dt);
return dt; //返回Datatable
}

❽ sql資料庫中的image類型要怎麼存圖片存了之後如何用C#語言在visualstudio中用picturebox顯示

這種存放數據流的方式還是很少用的.winform還可以,畢竟區域網多一些.asp.net還是別用了.

首先:資料庫中建立二進制欄位,也就是byte類型.

再次:把image轉為byte[],然後存入資料庫.

最後:從資料庫中取出byte[]轉為image,給picturebox顯示.

下面是FileStream和byte[]互轉的代碼

//文件轉byte
privatebyte[]FileToByte(stringfilepath)
{
byte[]arrFile=null;
using(FileStreamfs=newFileStream(filepath,FileMode.Open))
{
arrFile=newbyte[fs.Length];
fs.Read(arrFile,0,arrFile.Length);
}
returnarrFile;
}

//Byte轉文件
privateboolByteToFile(byte[]pReadByte,stringfileName)
{
FileStreampFileStream=null;
try
{
pFileStream=newFileStream(fileName,FileMode.OpenOrCreate);
pFileStream.Write(pReadByte,0,pReadByte.Length);
}
catch
{
returnfalse;
}
finally
{
if(pFileStream!=null)
pFileStream.Close();
}
returntrue;
}

❾ SQL的IMAGE長度該如何獲取

返回任何錶達式所佔用的位元組數。

語法
DATALENGTH ( expression )

參數
expression

任何類型的表達式。

返回類型
int

注釋
DATALENGTH 對 varchar、varbinary、text、image、nvarchar 和 ntext 數據類型特別有用,因為這些數據類型可以存儲
可變長度數據。

NULL 的 DATALENGTH 的結果是 NULL。

說明 兼容級別可能影響返回值。有關兼容級別的更多信息,請參見 sp_dbcmptlevel。

示例
此示例查找 publishers 表中 pub_name 列的長度。

USE pubs
GO
SELECT length = DATALENGTH(pub_name), pub_name
FROM publishers
ORDER BY pub_name
GO

下面是結果集:

length pub_name
----------- ----------------------------------------
20 Algodata Infosystems
16 Binnet & Hardley
21 Five Lakes Publishing
5 GGG&G
18 Lucerne Publishing
14 New Moon Books
17 Ramona Publishers
14 Scootney Books

(8 row(s) affected)

❿ ASP.net圖片和其他信息上傳到sql資料庫,在另外一個頁面用gridview和image控制項顯示出來

給你說一個解決方法
上傳就根據網上的方法介紹的
將文件上傳到指定文件夾比如(upload)之後
獲取到上傳文件的文件名
只將文件名寫入到資料庫中
image控制項讀取的時候,講image的url設置為「upload」+從資料庫里讀出的imgurl+;
調試的時候一定要注意相對路徑的問題 通常圖片不能正常顯示都是這個問題
運行的時候設置一下斷點 看看最終的url是什麼就能知道錯誤在哪裡了
祝你成功!