當前位置:首頁 » 操作系統 » c圖片資料庫

c圖片資料庫

發布時間: 2022-09-08 23:59:07

『壹』 C#winform 中上傳圖片保存到資料庫

就是2中方法:
1:上傳圖片的相對路徑到資料庫中相應欄位里,讀取顯示時,將控制項(假設用的是Image控制項)的ImageUrl屬性指向該相對路徑即可。

2:將圖片以二進制流的方式整體上傳到資料庫里,讀取顯示時,以二進制流的方式整體讀出。這種方法稍微麻煩一點,但保存的是圖片整體到資料庫里。

『貳』 用簡單的語言講下怎麼建立一個小型儲存圖片的資料庫

大部分資料庫都可以直接存儲圖片,小的可以用ACCESS
大的用MYsql
如果數據量不大
用ACCESS應該就夠了
至於編程語言
c
c++
c#
java
VB
等都可以
需要具有一定的編程能力
SQLSERVER
是大中型系統開發用的
如果只是存儲一點圖片的話
沒必要用

『叄』 C#WinForm中,用於將圖片以二進制存入sql資料庫中,並將圖片從資料庫中取出,顯示在PictureBox控制項中。

插入: //單擊圖片選擇添加的圖片 private void pic_Click(object sender, EventArgs e)
{ dlg.Filter = "JPG|*.jpg|BMP|*.bmp|PNG|*.png";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
pic.Image = Image.FromFile(dlg.FileName);
txtFilePath = dlg.FileName;
}
} public byte[] picData; public string txtFilePath = ""; 添加確定按鈕代碼: f (txtFilePath != "")
{
try
{
FileStream fs = new FileStream(txtFilePath, FileMode.Open, FileAccess.Read);
int len = Convert.ToInt32(fs.Length);
b = new byte[len];
fs.Read(b, 0, len);
fs.Close();
}
catch
{
b = null;
}
} SqlConnection conn = new SqlConnection(strConn);
conn.Open(); SqllCommand cmdInsert = new SqlCommand();
cmdInsert.Connection = conn;
cmdInsert.CommandText =插入語句; cmdInsert.Parameters.Add("@照片", SqlDbType.Image); if (txtFilePath == "")
{
cmdInsert.Parameters["@照片"].Value = DBNull.Value;
}
else
{
cmdInsert.Parameters["@照片"].Value = b;
}
cmdInsert.ExecuteNonQuery();
conn.Close();獲取: public byte[] picData; SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from 聯系人 where 編號=" + ID.ToString();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet(); sda.Fill(ds); if (ds.Tables[0].Rows.Count == 1)
{
if (ds.Tables[0].Rows[0]["照片"] == DBNull.Value)
{ //pic為picturebox控制項
pic.Image = PhoneBoook.Properties.Resources.DeskShade;//為空的話給個默認圖片
}
else
{
byte[] b = (byte[])(ds.Tables[0].Rows[0]["照片"]);
pic.Image = Image.FromStream(new MemoryStream(b));
picData = b;
}
}

『肆』 (網頁)圖片的路徑c:/images/123.jpg 保存在資料庫中,如何讀出

打開資料庫,然後讀出<img src=<% =圖片的路徑%> width="" height="">

『伍』 用c/c++語言在mysql資料庫的表banana中插入一張圖片,然後再刪除一張圖片,請給出完整代碼

msql裡面有相應的sdk包,參考裡面的內容。如果這都做不了建議你別做程序員了

『陸』 有一個圖片保存在"c:/123/123.jpg",如何把它的路徑保存到資料庫並讀出來

在wwwroot目錄建立一個目錄,例如images,將圖片保存在這個目錄中,在資料庫建立一個欄位,例如LJ,在這個欄位中輸入:/images/123.jpg即可。

『柒』 VS.C#如何向數據資料庫中存入和讀取圖片的

首先,在資料庫中要建立相應的欄位能保存Bytes,例如在SQL Server中用Image類型來定義欄位。我所用到的資料庫大致結構如下:

欄位名
類型
備注

FileID
Int
自增欄位

FileName
Varchar(256)

FullName
Varchar(1024)

FileData
Image

然後就是寫入資料庫,代碼如下:

FileInfo fi = new FileInfo( txtFileName.Text );// Replace with your file name

if ( fi.Exists)

{

byte[] bData = null;

int nNewFileID = 0;

// Read file data into buffer

using ( FileStream fs = fi.OpenRead() )

{

bData = new byte[fi.Length];

int nReadLength = fs.Read( bData,0, (int)(fi.Length) );

}

// Add file info into DB

string strQuery = "INSERT INTO FileInfo "

+ " ( FileName, FullName, FileData ) "

+ " VALUES "

+ " ( @FileName, @FullName, @FileData ) "

+ " SELECT @@IDENTITY AS 'Identity'";

SqlCommand sqlComm = new SqlCommand( strQuery, sqlConn );

sqlComm.Parameters.Add( "@FileName", fi.Name );

sqlComm.Parameters.Add( "@FullName", fi.FullName );

sqlComm.Parameters.Add( "@FileData", bData );

// Get new file ID

SqlDataReader sqlReader = sqlComm.ExecuteReader();

if( sqlReader.Read() )

{

nNewFileID = int.Parse(sqlReader.GetValue(0).ToString());

}

sqlReader.Close();

sqlComm.Dispose();

if( nNewFileID > 0 )

{

// Add new item in list view

ListViewItem itmNew = lsvFileInfo.Items.Add( fi.Name );

itmNew.Tag = nNewFileID;

}

}

而讀出的代碼如下:

// Get new file name

string strFullName = dlgFBSave.SelectedPath;

if( strFullName[strFullName.Length - 1] != '\\' )

strFullName += @"\";

strFullName += lsvFileInfo.SelectedItems[0].Text;

string strQuery = "SELECT FileData FROM FileInfo "

+ " WHERE FileID = " + lsvFileInfo.SelectedItems[0].Tag.ToString();

SqlDataAdapter sqlDAdapter = new SqlDataAdapter(strQuery,sqlConn);

DataSet sqlRecordSet = new DataSet();

byte[] bData = null;

//Get file data from DB

try

{

sqlDAdapter.Fill( sqlRecordSet, "FileInfo" );

foreach( DataRow dr in sqlRecordSet.Tables["FileInfo"].Rows)

{

if( dr["FileData"] != DBNull.Value )

bData = ( byte[] )dr["FileData"];

}

}

catch(SqlException sqlErr)

{

MessageBox.Show( sqlErr.Message );

}

catch

{

MessageBox.Show( "Failed to read data from DB!" );

}

sqlRecordSet.Dispose();

sqlDAdapter.Dispose();

if( bData != null )

{

// Save file

FileInfo fi = new FileInfo( strFullName );

if( !fi.Exists )

{

//Create the file.

using (FileStream fs = fi.Create())

{

fs.Write( bData, 0, bData.Length);

}

}

else

{

//Create the file.

using (FileStream fs = fi.OpenWrite())

{

fs.Write( bData, 0, bData.Length);

}

}

}

不過需要提的一點,如果把大量的文件存入資料庫的話,會造成資料庫的臃腫,而且訪問量也會增大。所以現在比較流行的做法,是把文件上傳到伺服器上,而在資料庫上只保存文件的相對路徑即可。那麼訪問的時候,先通過資料庫得到文件的相對路徑,然後再訪問伺服器上的文件

『捌』 c#從資料庫中提取圖片

很簡單
如果沒別的要求的話
你在第一個image裡面綁定一個數據集或則直接查詢出第一條數據賦值給它
然後再查詢TOP6分別賦值給下面的6個IMAGE 就可以了
數據查詢不用我寫了吧
把查詢的結果放在DATATABLE裡面也沒問題吧
賦值就更簡單了 IAMGE1.imageurl = dt.rows[0]["圖片的URL"].ToString();
還有什麼問題的話 給我留言

『玖』 c#怎樣從資料庫讀取圖片並保存到指定文件

SqlDataAdapter da = new SqlDataAdapter("select * from newpicture", conn);
DataSet ds = new DataSet();
da.Fill(ds, "pic");

string picdotname;
string picfilename;
int piclength;
int i;
//添加新列
DataColumn newcolumn = ds.Tables["pic"].Columns.Add("pic_url", typeof(string));
for (i = 0; i < Convert.ToInt16(ds.Tables["pic"].Rows.Count); i++)
{
picdotname = ds.Tables["pic"].Rows[i]["pic_dot"].ToString();
piclength = Convert.ToInt32(ds.Tables["pic"].Rows[i]["pic_length"]);
picfilename = Server.MapPath("temp/") + "temp" + i.ToString() + "." + picdotname;
FileStream fs = new FileStream(picfilename, FileMode.Create, FileAccess.Write);
byte[] piccontent = new byte[piclength];
piccontent = (byte[])ds.Tables["pic"].Rows[i]["pic_content"];
fs.Write(piccontent, 0, piclength);
fs.Close();
ds.Tables["pic"].Rows[i]["pic_url"] = "temp/temp" + i.ToString() + "." + picdotname;//相對路徑,改成你自己的文件夾
}
數據源 = ds.Tables["pic"];//數據綁定
大體是這樣吧,裡面表名列名很多細節你按你的表修改吧!
用哪個控制項都行,只要圖片路徑正確就能顯示的

『拾』 vc mfc中怎麼通過按鈕 「上傳圖片」把本機上的圖片讀入SQL資料庫

圖片就是文件嘛,把文件數據全部讀入到內存然後插入到
sql資料庫
中就可以了,但不建議這樣做,因為圖片數據比較大,存入資料庫會很慢,檢索也會很慢,建議只存入圖片的路徑,比如你要存入的圖片為c:\\test.bmp,那麼你存入數據的信息就為c:\\test.bmp,當有地方要使用該圖片時,只需取出c:\\test.bmp這個路徑就可以操作該圖片了。

熱點內容
如何獲得列印機無線密碼 發布:2024-05-04 06:44:59 瀏覽:416
上古諸神錄哪裡改密碼 發布:2024-05-04 06:43:55 瀏覽:261
灌籃高手手游自動蓋帽腳本 發布:2024-05-04 06:42:31 瀏覽:423
javajs引擎 發布:2024-05-04 06:37:33 瀏覽:796
javalist重復 發布:2024-05-04 06:19:27 瀏覽:509
max腳本管理 發布:2024-05-04 06:02:31 瀏覽:44
自行搭建伺服器 發布:2024-05-04 06:01:12 瀏覽:125
h3c如何查看所有配置 發布:2024-05-04 05:26:39 瀏覽:493
java統計字元串中字母個數 發布:2024-05-04 05:22:58 瀏覽:888
throwablejava 發布:2024-05-04 05:22:56 瀏覽:792