不需要原,实际上你可以把它理解成文件流。所以说你只需要读取到数据库的二进制到然后解析还原成原就可以了。像你这种情况应该是还原的方法不对或者是二进制有问题。
这是我的一段你参照下看可以不:
byte[] MyData = new byte[0];
if (MyData != null && !RowGetString("CstSignature")IsNullOrEmpty())
{
MyData = (byte[])Row["CstSignature"];//读取第一个的位流
int ArraySize = MyDataGetUpperBound(0);//获得数据库中存储的位流数组的维度上限,用作读取流的上限
FileStream fs = new FileStream(@"c:/00jpg", FileModeOpenOrCreate, FileAccessWrite);
fsWrite(MyData, 0, ArraySize);
fsClose(); //-- 写入到c:/00jpg。
(thisFindControl("picPhoto") as StarPictureBox)Image = ImageFromFile("c:/00jpg");
}
1 C#中怎么把数据保存到ACCESS数据库
Sqlmand是 *** 作sql数据库的,Access用OleDbmand首先定义一个链接对象OleDbConnection conn = new OleDbConnection("[数据库连接字符串]");connOpen(); 打开数据库连接OleDbmand cmd = new OleDbmand("[Insert/Update/Delte语句]", conn);cmdExecuteNonQuery(); 执行 *** 作,如果是查询则不是用这个方法 最后别忘记关闭数据库连接和释放对象。
2 C# 如何将 直接存入SQL数据库中
把文件转成二进制流出入数据库
private void button2_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(textBox1Text, FileModeOpen);
BinaryReader br = new BinaryReader(fs);
Byte[] byData = brReadBytes((int)fsLength);
fsClose();
string conn = "server=;database=testDB;Uid=sa;Pwd=sa ";
SqlConnection myconn = new SqlConnection(conn);
myconnOpen();
string str = "insert into pro_table (pro_name,pro_file) values('测试文件',@file)";
Sqlmand mym = new Sqlmand(str, myconn);
mymParametersAdd("@file", SqlDbTypeBinary, byDataLength);
mymParameters["@file"]Value = byData;
mymExecuteNonQuery();
myconnClose();
}
从数据库中把二进制流读出写入还原成文件
private void button4_Click(object sender, EventArgs e)
{
string conn = "server=;database=testDB;Uid=sa;Pwd=sa ";
string str = "select pro_file from pro_table where pro_name='测试文件' ";
SqlConnection myconn = new SqlConnection(conn);
SqlDataAdapter sda = new SqlDataAdapter(str, conn);
DataSet myds = new DataSet();
myconnOpen();
sdaFill(myds);
myconnClose();
Byte[] Files = (Byte[])mydsTables[0]Rows[0]["pro_file"];
BinaryWriter bw = new BinaryWriter(FileOpen("D:\\2rdlc",FileModeOpenOrCreate));
bwWrite(Files);
bwClose();
}
3 c#如何把存取到SQL数据库
一楼开玩笑了!!可以保存到数据库的。
首先,你的数据库里要有一个存放二进制数据的字段。然后,用一个文件选择控件,让用户选择。
用FileStreamRead把文件按照二进制读取到byte[]中,接下来,链接数据库,用sql语句,进行相应的插入 *** 作,将数据库的二进制数据的字段赋值为byte[]就行了。以下是保存和显示的代码:private void SaveImage(string fileName) { Read the file into a byte array using (FileStream fs = new FileStream(fileName, FileModeOpen, FileAccessRead)) { byte[] imageData = new Byte[fsLength]; fsRead(imageData, 0, (int)fsLength); using (SqlConnection conn = new SqlConnection(connectionString)) { string sql = "insert into image (imagefilename,blobdata) values (@filename,@blobdata)"; Sqlmand cmd = new Sqlmand(sql, conn); cmdParametersAdd("@filename",SqlDbTypeText); cmdParameters["@filename"]Direction = ParameterDirectionInput; cmdParametersAdd("@blobdata", SqlDbTypeImage); cmdParameters["@blobdata"]Direction = ParameterDirectionInput; Store the byte array within the image field cmdParameters["@filename"]Value = fileName; cmdParameters["@blobdata"]Value = imageData; connOpen(); if (cmdExecuteNonQuery() == 1) { MessageBoxShow("Done"); } } } } private void LoadImage(string fileName) { using (SqlConnection conn = new SqlConnection(connectionString)) { string sql = "select blobdata from Image where ImageFileName like @filename"; Sqlmand cmd = new Sqlmand(sql, conn); cmdParametersAdd("@filename", SqlDbTypeText); cmdParameters["@filename"]Value = fileName; connOpen(); object objImage = cmdExecuteScalar(); byte[] buffer = (byte[])objImage; BinaryWriter bw = new BinaryWriter(new FileStream("C:\\abcd", FileModeCreate)); bwWrite(buffer); bwClose(); MemoryStream ms = new MemoryStream(buffer); Image bgImage = ImageFromStream(ms); msClose(); thisBackgroundImage = bgImage; } } ------------------------------------------------------------------PS:用空情报我踩踩空间,谢谢。
/kxl361。
4 如何将文件的路径存入SQL数据库中去
建一个表:JpgFiles,其中至少包含一个列:JpgPath,用来存放绝对路径的字符串,所以这个列需要用varchar,长度假设为50,不够的话自己再增加。
string strPath = @"d:\baidu\up";
string[] fileNames = SystemIODirectoryGetFiles(strPath);
SqlConnection Cn=new SqlConnection(这里写你的连接串);
Sqlmand Cmd=new Sqlmand("Insert JpgFiles values (@JpgPath)",Cn)
CmdParametersAdd("@JpgPath",SqlDbTypeVarChar,50);
foreach (string strName in fileNames)
{
CmdParameters[0]Value=strName;
CmdExecuteNoQuery();
}
5 怎样将数据存入mysql数据库
MySQL命令行导出数据库:
1,进入MySQL目录下的bin文件夹:cd MySQL中到bin文件夹的目录
如我输入的命令行:cd C:\Program Files\MySQL\MySQL Server 41\bin
(或者直接将windows的环境变量path中添加该目录)
2,导出数据库:mysqldump -u 用户名 -p 数据库名 >; 导出的文件名
如我输入的命令行:mysqldump -u root -p news > newssql (输入后会让你输入进入MySQL的密码)
(如果导出单张表的话在数据库名后面输入表名即可)
3、会看到文件newssql自动生成到bin文件下
命令行导入数据库:
1,将要导入的sql文件移至bin文件下,这样的路径比较方便
2,同上面导出的第1步
3,进入MySQL:mysql -u 用户名 -p
如我输入的命令行:mysql -u root -p (输入同样后会让你输入MySQL的密码)
4,在MySQL-Front中新建你要建的数据库,这时是空数据库,如新建一个名为news的目标数据库
5,输入:mysql>use 目标数据库名
如我输入的命令行:mysql>use news;
6,导入文件:mysql>source 导入的文件名;
如我输入的命令行:mysql>source newssql;
6 如何把文件存入到sql server 2008
1MDF文件
在企业管理器中
右击数据库
点击所有任务
附加数据库
点三个点选择文件
选中U盘中的MDF文件确定即可
2BAK等备份文件:
新建空数据库,取名最好为原数据库名
右击新建的数据库
点所有任务
点还原数据库
点从设备
点选择设备
点添加
定位到U盘中您的备份的文件
确定
点选项
点在现有数据库上强制还原
点确定
等待
完成!
另外,站长团上有产品团购,便宜有保证
1用语句在VS2008中创建数据库的语句:
USE [master]
GO
/ Object: Database [test] Script Date: 04/10/2010 22:06:45 /
CREATE DATABASE [test] ON PRIMARY
( NAME = N'test', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL1\MSSQL\DATA\testmdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'test_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL1\MSSQL\DATA\test_logldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
COLLATE Chinese_PRC_CI_AS
GO
EXEC dbosp_dbcmptlevel @dbname=N'test', @new_cmptlevel=90
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [test][dbo][sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [test] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [test] SET ANSI_NULLS OFF
GO
ALTER DATABASE [test] SET ANSI_PADDING OFF
GO
ALTER DATABASE [test] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [test] SET ARITHABORT OFF
GO
ALTER DATABASE [test] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [test] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [test] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [test] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [test] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [test] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [test] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [test] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [test] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [test] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [test] SET ENABLE_BROKER
GO
ALTER DATABASE [test] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [test] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [test] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [test] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [test] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [test] SET READ_WRITE
GO
ALTER DATABASE [test] SET RECOVERY FULL
GO
ALTER DATABASE [test] SET MULTI_USER
GO
ALTER DATABASE [test] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [test] SET DB_CHAINING OFF
2在上面建立的数据库中建立一个表:
CREATE TABLE dbotest
(
c_id nchar(10) NOT NULL,
c_name nchar(10) NULL
) ON [PRIMARY]
GO
COMMIT
3向上面建好的表中插入一个数据:
insert into dbotest values(11,12)
4在表上建立触发器的数据:
CREATE TRIGGER test_trigger
ON dbotest AFTER INSERT
AS
BEGIN
insert into dbotest values(11,12);
END
<%
dim conn,db
dim connstr
db="dbmdb" ' access数据库文件路径
connstr="Provider=MicrosoftJetOLEDB40;Data Source="&serverMapPath(""&db&"")&";Persist Security Info=False;"
set conn=servercreateobject("ADODBCONNECTION")
'连接数据库
connopen connstr 'open datebase
'数据库结构
'文件名dbmdb
'表名admin
'字段id,自动编号
'字段username,文本
'字段userpass,文本
' 增
set Rs=servercreateobject("adodbrecordset")
Sql="select from admin"
Rsopen Sql,conn,1,3
Rsaddnew
Rs("username")="用户名"
Rs("userpass")="用户密码"
Rsupdate
Rsclose
set Rs=nothing
responseWrite "<script language='javascript'>alert('管理员增加成功!');'</script>"
' 删
s_id=1 '假设有个用户数据的id为1
Sql="delete from admin where id="&s_id&""
set Rs=serverCreateObject("ADODBrecordset")
rsopen Sql,conn,1,3
responseWrite("<script>alert('帐号删除成功!');</script>")
rsclose
set Rs=nothing
' 改
s_id=1 '假设有个用户数据的id为1
set Rs=servercreateobject("adodbrecordset")
Sql="select from admin where id="&s_id&""
Rsopen Sql,conn,1,3
if Rseof and Rsbof then
Rsclose
set Rs=nothing
responseWrite("<script language='javascript'>alert('此用户不存在!');historyback();</script>")
else
Rs("Password")="新密码"
Rsupdate
Rsclose
set Rs=nothing
responseWrite ("<script language='javascript'>alert('密码修改成功!');</script>")
End If
' 查单个
s_username="admin" '假设有个用户名为admin的用户数据
set Rs=servercreateobject("adodbrecordset")
Sql="select from admin where username='"&s_username&"'"
Rsopen Sql,conn,1,3
if Rseof and Rsbof then
Rsclose
set Rs=nothing
responseWrite("<script language='javascript'>alert('此用户不存在!');historyback();</script>")
else
s_name=Rs("username")
s_pass=Rs("userpass")
Rsclose
set Rs=nothing
' 输出查询到的信息
responseWrite ("<script language='javascript'>alert('你查询的用户名"&s_name&"的密码为:"&s_pass&"');</script>")
End If
' 查列表
set Rs=serverCreateObject("Adodbrecordset")
sql="select from admin order by id desc"
Rsopen sql,conn,1,1
if not Rseof then
' 循环输出查询到的信息
do while not Rseof
responseWrite "id:"&Rs("id")&",用户名:"&Rs("username")&",密码:"&Rs("userpass")&"<br />"
Rsmovenext
loop
end if
Rsclose
set Rs=nothing
' 使用完数据库后要关闭连接资源
connclose
set conn=nothing
%>
ASP与SQL数据库连接语句具体如下:
Set conn = ServerCreateObject("ADODBConnection")
connstr = "provider=Sqloledb;server=服务器名;uid=用户名;pwd=密码;database=数据库名"
connOpen connstr
If Err Then
errClear
Set conn = Nothing
ResponseWrite "数据库连接出错,请检查连接字串"
ResponseEnd
扩展资料:
SQL常用命令使用方法:
(1) 数据记录筛选:
sql="select from 数据表 where 字段名=字段值 order by 字段名 "
sql="select from 数据表 where 字段名 like ‘%字段值%‘ order by 字段名 "
sql="select top 10 from 数据表 where 字段名 order by 字段名 "
sql="select from 数据表 where 字段名 in (‘值1‘,‘值2‘,‘值3‘)"
sql="select from 数据表 where 字段名 between 值1 and 值2"
(2) 更新数据记录:
sql="update 数据表 set 字段名=字段值 where 条件表达式"
sql="update 数据表 set 字段1=值1,字段2=值2 …… 字段n=值n where 条件表达式"
(3) 删除数据记录:
sql="delete from 数据表 where 条件表达式"
sql="delete from 数据表" (将数据表所有记录删除)
导出SQL脚本,只能导出这个数据表“结构”的创建SQL语句要导出数据表的数据,只能用“导入和导出数据”工具来处理或自已写 insert into 语句来补充默认数据 追问: 要导出 TXT 文本 包括表里面的数据 导出也行 回答: 可以把结果集查询出来后,直接另存 追问: 查询出 脚本 ? 回答: 恩这样也可以的。<!--#include file="inc/connasp"--><%dim rs,sql,filename,fso,myfile,xSet fso = serverCreateObject("scriptingfilesystemobject")filename = ServerMapPath("downloadtxt")if fsoFileExists(filename) thenfsoDeleteFile(filename)end if'--创建txt文件set myfile = fsoCreateTextFile(filename,true)Set rs = ServerCreateObject("ADODBRecordset")sql = "select from userfile"rsOpen sql,conn,1,1if rsEOF and rsBOF thenresponsewrite "无数据"elsedim strLine,responsestrstrLine=""'--将表的列名先写入txtFor each x in rsfieldsstrLine = strLine & xname & chr(9)Nextmyfilewriteline strLineDo while Not rsEOFstrLine=""for each x in rsFieldsstrLine = strLine & xvalue & chr(9)next'--将表的数据写入txtmyfilewriteline strLinersMoveNextloopend ifrsCloseset rs = nothing
1提取单条记录
//using SystemData;
//using SystemDataSqlClient;
using (SqlConnection cn = new SqlConnection(%%1))
//ConfigurationManagerConnectionStrings["db2ConnectionString"]ConnectionString
//Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
{
SqlCommand cmd = new SqlCommand("Select Count() From jobs",cn);
cnOpen();
%%2=cmdExecuteScalar(); //MessageInnerHtml
}
2单值比较
//using SystemData;
//using SystemDataSqlClient;
using (SqlConnection cn = new SqlConnection(%%1))
//ConfigurationManagerConnectionStrings["db2ConnectionString"]ConnectionString
//Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
{
SqlCommand cmd = new SqlCommand("Select Count() From jobs",cn);
cnOpen();
%%2=cmdExecuteScalar(); //MessageInnerHtml
if(%%2==%%3)
{
%%4
}
}
3显示表格
//using SystemData;
//using SystemDataSqlClient;
DataSet ds=null;
using (SqlConnection cn = new SqlConnection(%%1))
//ConfigurationManagerConnectionStrings["db2ConnectionString"]ConnectionString
//Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
{
cnOpen();
cmd=new SqlDataAdapter("Select From Author",cn);
ds=new DataSet();
cmdFill(ds,%%2); //"作者"
MyDataGridDataSource=dsTables(%%2)DefaultView; //"作者"
MyDataGridDataBind();
}
4 *** 作表格
//using SystemData;
//using SystemDataSqlClient;
using (SqlConnection cn = new SqlConnection(%%1))
//ConfigurationManagerConnectionStrings["db2ConnectionString"]ConnectionString
//Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
{
cnOpen();
cmd=new SqlDataAdapter("Select From Author",cn);
ds=new DataSet();
cmdFill(ds,%%2); //"作者"
MyDataGridDataSource=dsTables(%%2)DefaultView; //"作者"
MyDataGridDataBind();
}
5数值范围查询
//using SystemData;
//using SystemDataSqlClient;
using (SqlConnection cn = new SqlConnection(%%1))
//ConfigurationManagerConnectionStrings["db2ConnectionString"]ConnectionString
//Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
{
}
6关闭时断开连接
//using SystemData;
//using SystemDataSqlClient;
using (SqlConnection cn = new SqlConnection(%%1))
//ConfigurationManagerConnectionStrings["db2ConnectionString"]ConnectionString
//Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
{
}
7执行命令
//using SystemData;
//using SystemDataSqlClient;
using (SqlConnection cn = new SqlConnection(%%1))
//ConfigurationManagerConnectionStrings["db2ConnectionString"]ConnectionString
//Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
{
SqlCommand cmd = new SqlCommand("insert userRegister_t values('"
+ TextBox1Text + "','" + TextBox2Text + "')",cn);
cnOpen();
cmdExecuteNonQuery();
}
7Oracle8/8i/9i数据库(thin模式)
//using SystemData;
Oracle Set Your custom connection strings values
ODBC
New version
Driver={Microsoft ODBC for Oracle};Server=myServerAddress;Uid=myUsername;Pwd=myPassword;
Old version
Driver={Microsoft ODBC Driver for Oracle};ConnectString=OracleServerworld;Uid=myUsername;Pwd=myPassword;
OLE DB, OleDbConnection (NET)
Standard security
This connection string uses a provider from Microsoft
Provider=msdaora;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;
Standard Security
This connection string uses a provider from Oracle
Provider=OraOLEDBOracle;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;
Trusted Connection
Provider=OraOLEDBOracle;Data Source=MyOracleDB;OSAuthent=1;
OracleConnection (NET)
Standard
Data Source=MyOracleDB;Integrated Security=yes;
This one works only with Oracle 8i release 3 or later
Specifying username and password
Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;Integrated Security=no;
This one works only with Oracle 8i release 3 or later
Missing the SystemDataOracleClient namespace Download NET Managed Provider for Oracle >>
Great article! "Features of Oracle Data Provider for NET" by Rama Mohan G at C# Corner >>
Omiting tnsnamesora
This is another type of Oracle connection string that doesn't rely on you to have a DSN for the connection You create a connection string based on the format used in the tnsnamesora file without the need to actually have one of these files on the client pc
SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));uid=myUsername;pwd=myPassword;
Core Labs OraDirect (NET)
Standard
User ID=myUsername;Password=myPassword;Host=ora;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;
Read more at Core Lab >>
And at the product page >>
Data Shape
MS Data Shape
Provider=MSDataShape1;Persist Security Info=False;Data Provider=MSDAORA;Data Source=orac;User Id=myUsername;Password=myPassword;
16程序计时
DateTime runTime = ConvertToDateTime(SystemConfigurationConfigurationSettingsAppSettings["TimerRunAt"]);
//运行时间
TimeSpan runTime = new TimeSpan(runTimeTicks);
//现在时间
TimeSpan timeNow = new TimeSpan(DateTimeNowTicks);
//时间间隔
TimeSpan ts = runTimeSubtract(timeNow);
//如果运行时间与当前时间的差大于0,则任务执行时间为当日
if(tsTotalMilliseconds > 0)
{
return tsTotalMilliseconds;
}
//如果运行时间与当前时间的差小于0,则任务执行时间为次日
Else
{
//差值的绝对值应加1天
return tsDuration()Add(new TimeSpan(1,0,0,0,0))TotalMilliseconds;
}
17延时
//using SystemThreading;
ThreadSleep(Int32Parse(%%1));
18连接Excel文件
string connString = "Provider=MicrosoftJetOLEDB40;Data Source=" + excel文件名(绝对路径) +";Extended Properties=Excel 80;";
以上就是关于从sql数据库里显示或者输出二进制图片全部的内容,包括:从sql数据库里显示或者输出二进制图片、c怎么把数据存到sql、SQL数据库问题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)