C# 存图片到数据库的问题
现在数据库里只能存文本,我想存入图片,这是存文本的代码
protected void Button1_Click(object sender, EventArgs e)
{
//保存
string strHeadID = this.txtHeadID.Text.Trim();
string strCataID = this.txtCataID.Text.Trim();
DateTime dtDateTime = DateTime.Now;
string strText = this.txtText.Text;
string strTitle = this.txtTitle.Text;
strText = this.ReplayEmpty(strText);
strText = strText.Replace("\r\n", "</P><P>");
strText = "<P>" + strText;
strText = strText + "</P>";
//保存
string strSQL = string.Empty;
strSQL = "Insert Into TblNews(SortID,CatalogName,AddTime,NewsContent,NewsTitle) Values (";
strSQL += "'{0}','{1}','{2}','{3}','{4}')";
strSQL = string.Format(strSQL, new object[] {
strHeadID, strCataID, dtDateTime, strText,strTitle });
if (this.m_dbChunnel.RunDDLSql(strSQL) > 0)
{
}
else
{
Response.Write("数据保存失败,请重新再试!");
}
}
private string ReplayEmpty(string strText)
{
string str = string.Empty;
int i;
bool bReplayFlag = true;
for (i = 0; i < strText.Length; i++)
{
if (strText.Substring(i, 1) == "<")
{
bReplayFlag = false;
}
if (strText.Substring(i, 1) == ">")
{
bReplayFlag = true;
}
if (bReplayFlag && strText.Substring(i, 1) == " ")
{//替换
str += " ";
}
else
{
str += strText.Substring(i, 1);
}
}
return str;
}
希望实现存入图片的功能,还有上面只是保存,如何写修改的呢,等待高手!
protected void Button1_Click(object sender, EventArgs e)
{
//保存
string strHeadID = this.txtHeadID.Text.Trim();
string strCataID = this.txtCataID.Text.Trim();
DateTime dtDateTime = DateTime.Now;
string strText = this.txtText.Text;
string strTitle = this.txtTitle.Text;
strText = this.ReplayEmpty(strText);
strText = strText.Replace("\r\n", "</P><P>");
strText = "<P>" + strText;
strText = strText + "</P>";
//保存
string strSQL = string.Empty;
strSQL = "Insert Into TblNews(SortID,CatalogName,AddTime,NewsContent,NewsTitle) Values (";
strSQL += "'{0}','{1}','{2}','{3}','{4}')";
strSQL = string.Format(strSQL, new object[] {
strHeadID, strCataID, dtDateTime, strText,strTitle });
if (this.m_dbChunnel.RunDDLSql(strSQL) > 0)
{
}
else
{
Response.Write("数据保存失败,请重新再试!");
}
}
private string ReplayEmpty(string strText)
{
string str = string.Empty;
int i;
bool bReplayFlag = true;
for (i = 0; i < strText.Length; i++)
{
if (strText.Substring(i, 1) == "<")
{
bReplayFlag = false;
}
if (strText.Substring(i, 1) == ">")
{
bReplayFlag = true;
}
if (bReplayFlag && strText.Substring(i, 1) == " ")
{//替换
str += " ";
}
else
{
str += strText.Substring(i, 1);
}
}
return str;
}
希望实现存入图片的功能,还有上面只是保存,如何写修改的呢,等待高手!
...全文
相关推荐
C# asp.net 图片存进数据库二进制和读取
### C# ASP.NET 图片存进数据库二进制与读取#### 一、概述在Web开发中,经常需要处理图片数据。
C#保存图片到数据库。
注意,循环中应考虑异常处理,防止因用户中断或文件问题而影响其他图片的处理。通过以上步骤,我们实现了C#将图片保存到SQLite数据库的功能,同时支持查看和删除操作。
C#中word文档、图片以二进流存数据库和从数据库读出并打开
本篇文章将详细探讨如何在C#中将Word文档和图片以二进制流的形式存储到数据库,并从数据库中读取后进行显示。首先,我们要理解什么是二进制流。
C# 图片转成byte存入,数据库读取byte转成图片的类
在C#编程中,将图片转换为byte数组并存储到数据库,然后从数据库读取byte数组再还原为图片,是一种常见的处理方式。这种方式便于在不直接依赖文件系统的情况下管理和传输图像数据。
C#使用SQLite存取图片的示例
Source=your_database.db;Version=3;";// 创建SQLite连接对象SQLiteConnection connection = new SQLiteConnection


