c图片数据库
就是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这个路径就可以操作该图片了。