能!create table testimg (a int,b image);
go
insert testimg (a,b) values (2,'test');
再到DOS下执行
textcopy /S SERVERNAME /U sa /P  /D Northwind /T testimg /C b /W "where a = 2 " /F f:\tmp\1.ico /I /Z

解决方案 »

  1.   

    用xp_cmdshell "textcopy /S SERVERNAME /U sa /P  /D Northwind /T testimg /C b /W "where a = 2 " /F f:\tmp\1.ico /I /Z
    "
    也可以的.
      

  2.   

    image 类型:
    下面是一个拷贝图像到SQL Server的pubs数据库的例子, 表名pub_info, 字段名logo,图像文件名picture.bmp,保存到pub_id='0736'记录 
    sp_textcopy @srvn
    ame = 'ServerName', 
                @login = 'Login', 
                @password = 'Password', 
                @dbname = 'pubs', 
                @tbname = 'pub_info', 
                @colname = 'logo', 
                @filename = 'c:\picture.bmp', 
                @whereclause = " WHERE pub_id='0736' ", 
                @direction = 'I'
      

  3.   

    CREATE PROCEDURE sp_textcopy ( 
      @srvname    varchar (30), 
      @login      varchar (30), 
      @password    varchar (30), 
      @dbname      varchar (30), 
      @tbname      varchar (30), 
      @colname    varchar (30), 
      @filename    varchar (30), 
      @whereclause varchar (40), 
      @direction  char(1)) 
    AS 
    DECLARE @exec_str varchar (255) 
    SELECT @exec_str = 
            'textcopy /S ' + @srvname + 
            ' /U ' + @login + 
            ' /P ' + @password + 
            ' /D ' + @dbname + 
            ' /T ' + @tbname + 
            ' /C ' + @colname + 
            ' /W "' + @whereclause + 
            '" /F ' + @filename + 
            ' /' + @direction 
    EXEC master..xp_cmdshell @exec_str
      

  4.   

    这是一个java写的例子
    sun自带的jdbc-odbc桥的驱动,用sql server2000。
    import  java.util.*;
    import  java.io.*;
    import  java.sql.*;
    import  java.lang.*;
    /**将一个图像文件保存到数据库中
     */
    public class ImageTry {

    public static void main(String[] args){
    Connection conn = getConnection();
    PreparedStatement pstm =null;
    Statement stm =null;
    ResultSet res = null;
    FileInputStream fin = null;
    try{
    File f = new File("image.jpg");
    fin = new FileInputStream(f);

    String sql_1=" insert into table1(col_02) values(?)";
    //列col_02是image类型的
    pstm = conn.prepareStatement(sql_1);
    pstm.setBinaryStream(1,fin,(int)f.length());
    pstm.executeUpdate();
    fin.close();

    stm = conn.createStatement();
    String sql_2="select col_02 from table1";
    res = stm.executeQuery(sql_2); 
    if(res!= null && res.next()){
    outImage(res.getBinaryStream("col_02"));
    }
    }catch(Exception e){
    e.printStackTrace(System.out);
    }finally{
    if(fin != null){
    try{
    fin.close();
    }catch(IOException e){}
    }
    if(res != null){
    try{
    res.close();
    }catch(SQLException e){}
    }
    if(stm != null){
    try{
    stm.close();
    }catch(SQLException e){}
    }
    if(pstm != null){
    try{
    pstm.close();
    }catch(SQLException e){}
    }
    if(conn != null){
    try{
    conn.close();
    }catch(SQLException e){}
    }
    }
    }
    /**
     * 写到一个文件
     */
    static void outImage( InputStream din)
    throws IOException{
    File f = new File("im.jpg");
    FileOutputStream fout = null;
    try{
    fout = new FileOutputStream(f);
    int b ;
    while((b = din.read() )!=-1){
    fout.write(b);
    }
    }finally{
    if(din != null){
    try{
    din.close();
    }catch(IOException e){}
    }
    if(fout != null){
    try{
    fout.close();
    }catch(IOException e){}
    }
    }
    }
    /**取出一个连接 
     */
    public static Connection getConnection(){
    String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
    String sConnStr="jdbc:odbc:Test;UID=sa;PWD=";
    Connection ObjectCon=null;
    try{
      Class.forName(sDBDriver);
       ObjectCon=DriverManager.getConnection(sConnStr);
    }catch(Exception Error){
    System.out.println(Error);
    }
    return ObjectCon;
    }
    }
      

  5.   

    大家不觉得可笑吗?都能随便读取其他机器上的文件了,还有必要textcopy吗?
      

  6.   

    楼上,楼主没有给出用什么语言开发,能随便贴吗?在前台用可以呀!但用什么语言呢?
    delphi:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
       if OpenPictureDialog1.Execute then
       Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
       ADOTable1.Append;
       TBlobField(ADOTable1.FieldByName('FImage')).LoadFromFile(OpenPictureDialog1.FileName);
       ADOTable1.Post;
    end;
    还是bcb:
    if(DATABASE_STATE==INSERT)
    {
    AnsiString st;
    TMemoryStream *tmp = new TMemoryStream();
    DBI1->Picture->SaveToFile("TTT.jpg");
    tmp->LoadFromFile("TTT.jpg");
    DeleteFile("TTT.jpg");
    ADOQuery1->Parameters->ParamByName("PIC")->LoadFromStream(tmp,ftBlob);
    ADOQuery1->Parameters->ParamByName("TD")->Value=DP1->Date;
    st="摄于"+ DP1->Date;
    ADOQuery1->Parameters->ParamByName("JPEG")->Value=JpegOrBmp?"BMP":"JPEG";
    ADOQuery1->Parameters->ParamByName("IDI")->Value=MEM1->Text + st;
    ADOQuery1->Parameters->ParamByName("HEI")->Value=BT->Height;
    ADOQuery1->Parameters->ParamByName("WID")->Value=BT->Width;
    ADOQuery1->ExecSQL();
    ShowMessage("保存" + IntToStr(tmp->Size ));
    ShowMessage("成功保存图片!");
    delete tmp;
    return;
    }
    还是上面写的java??
    答题要有题目才行呀!你考试都不看题目的吗?
      

  7.   

    这段代码,可以在网页上传任何文件(图像,doc..)到数据库,
    你可以参考一下,有时间再和你多聊一下
    public void myInsert()
    {
    Int32 intFileLength;
    string strFileType;
    string strFileName;
    Stream stmFile;
    strFileName="";
    strFileName=FileBox1.PostedFile.FileName;
    intFileLength=FileBox1.PostedFile.ContentLength;
    strFileType=FileBox1.PostedFile.ContentType;
    //strFileType="dd";
    stmFile=FileBox1.PostedFile.InputStream;
    byte[] ByteFile=new byte[intFileLength];
    stmFile.Read(ByteFile,0,intFileLength);
    /*
    FileStream fs = new FileStream("aa.doc", FileMode.Open);
    BinaryReader br = new BinaryReader(fs);
    byte[] DocByte = br.ReadBytes((int)fs.Length);
    fs.Close();
    */
    SqlConnection myCon=new SqlConnection("server=(local);database=test;uid=sa;pwd=");
    string strCom="INSERT INTO FileByField Values(@Name,@FileData,@FileType,@FileLength)";
    SqlCommand myCom=new SqlCommand(strCom,myCon);
    myCom.Parameters.Add("@Name",SqlDbType.Char,255);
    myCom.Parameters.Add("@FileData",SqlDbType.Image);
    myCom.Parameters.Add("@FileType",SqlDbType.Char,255);
    myCom.Parameters.Add("@FileLength",SqlDbType.BigInt);

    myCom.Parameters["@Name"].Value=strFileName;
    myCom.Parameters["@FileData"].Value=ByteFile;
    myCom.Parameters["@FileType"].Value=strFileType;
    myCom.Parameters["@FileLength"].Value=intFileLength;
    myCon.Open();
    try
    { myCom.ExecuteNonQuery(); }
    catch(SqlException e)
    {
    if(e.Number==2627)
    Response.Write("PrimaryKey Error");
    else
    Response.Write("Other Error");
    }
    myCon.Close();
    BindData();
    }