我找到一些代码,但不好用,不懂C#,所以来这里请教大家了!  SqlConnection conn =null;  SqlCommand cmd = null;  SqlParameter param = null;  FileStream fs = null;  const string sConn = "server=(local);Initial  Catalog=Northwind;UID=ctester;PWD=password";  try {     conn = new SqlConnection(sConn);     cmd = new SqlCommand("UPDATE Categories SET Picture = ?Picture WHERE     CategoryName = 'Seafood'", conn);     fs = new FileStream("c:\\Builder.doc", FileMode.Open, FileAccess.Read);     Byte[] blob = new Byte[fs.Length];     fs.Read(blob, 0, blob.Length);     fs.Close();     param = new SqlParameter("Picture", SqlDbType.VarBinary, blob.Length,     ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blob);     cmd.Parameters.Add(param);     conn.Open();     cmd.ExecuteNonQuery();  } catch (SqlException e){   Console.Write("SQL Exception: " + e.Message());  } catch (Exception e) {   Console.Write("Exception: " e.Message());  }实际上,就是如何将一个 byte[] 更新到mysql的BLOB上面,不是Insert 是 update 操作!

解决方案 »

  1.   


    cmd = new SqlCommand("UPDATE Categories SET Picture =@Picture Picture WHERE
    new SqlParameter("Picture", byte[])
      

  2.   

    SqlConnection conn =null;//连接字符串来用的  SqlCommand cmd = null; //执行SQL语句  SqlParameter param = null;//传参数来用的  FileStream fs = null;//文件流  const string sConn = "server=(local);Initial  Catalog=Northwind;UID=ctester;PWD=password";//SQL的连接字符串  try {        conn = new SqlConnection(sConn);//实利化连接字符串        cmd = new SqlCommand("UPDATE Categories SET Picture = ?Picture WHERE        CategoryName = 'Seafood'", conn);//SQL语句        fs = new FileStream("c:\\Builder.doc", FileMode.Open, FileAccess.Read);//用文件流读取c:\\Builder.doc        Byte[] blob = new Byte[fs.Length];//一个Byte数组        fs.Read(blob, 0, blob.Length);//读取文件流        fs.Close();//关闭文件流        param = new SqlParameter("Picture", SqlDbType.VarBinary, blob.Length,        ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blob);//传入的参数        cmd.Parameters.Add(param);//添加到数据库里面        conn.Open();//关闭数据库连接        cmd.ExecuteNonQuery();//反回受影响行数  } catch (SqlException e){      Console.Write("SQL Exception: " + e.Message());//异常  } catch (Exception e) {      Console.Write("Exception: " e.Message());//异常  }
      

  3.   

    不是MySQL的数据库么,怎么看着使用的全是SQL Server的
      

  4.   

    MySQL/MSSQL?
    如果文件比较大的话,需要循环读取文件内容,。
    MSSQL下面是:
    UPDATETEXT { table_name.dest_column_name dest_text_ptr }
        { NULL | insert_offset }
         { NULL | delete_length }
         [ WITH LOG ]
         [ inserted_data
        | { table_name.src_column_name src_text_ptr } ]如果2005等较新的版本,用write 子 句的update.
    USE AdventureWorks;
    GO
    DECLARE @MyTableVar table (
        DocumentID int NOT NULL,
        SummaryBefore nvarchar(max),
        SummaryAfter nvarchar(max));
    UPDATE Production.Document
    SET DocumentSummary .WRITE (N'features',28,10)
    OUTPUT INSERTED.DocumentID,
           DELETED.DocumentSummary, 
           INSERTED.DocumentSummary 
        INTO @MyTableVar
    WHERE DocumentID = 3 ;
    SELECT DocumentID, SummaryBefore, SummaryAfter 
    FROM @MyTableVar;
    GO
      

  5.   

    如果数据库是Mysql的话,连接不能用sqlconnection了,可能是oledbconnection类别,或者专门为Mysql开发的ADO.Net库。
      

  6.   


    OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["NEWOracleConn"].ToString());
                OracleCommand cmd = new OracleCommand("UPDATE TUSER SET PHOTO=:photo   WHERE userid=:id", conn);
                Console.WriteLine(cmd.CommandText);
                cmd.Parameters.Add("photo",OracleType.Blob);
                cmd.Parameters["photo"].Value = photo;
                cmd.Parameters.Add("id", OracleType.Number);
                cmd.Parameters["id"].Value = id;
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();   参考 我这段代码是更新Oracle中的blob字段
      

  7.   

      MySql.Data.MySqlClient.MySqlCommand cmm = null;
      cmm = new MySql.Data.MySqlClient.MySqlCommand("", connect);
       MySql.Data.MySqlClient.MySqlParameter param = null;
       param = new MySql.Data.MySqlClient.MySqlParameter("?Picture", System.Data.DbType.Binary);
        param.Value = System.Text.Encoding.Default.GetBytes("");
      cmm.Parameters.Add(param);
    cmm.ExecuteNonQuery();
      

  8.   


     OracleCommand cmd = new OracleCommand("UPDATE TUSER SET PHOTO=:photo   WHERE userid=:id", conn);
    //注意这里是  冒号  不是@  也不是?  我是使用的OracleClien操作的Oracle
      

  9.   

    学习顺便逛逛...
    http://bbs.erp100.com/?fromuid=155581
      

  10.   

    我懂 C#      问题是 我不懂MySql
      
      

  11.   

    使用 SUN的  System.Data.MySqlClient 这个 数据接口调用的吧 
    这个和 System.Data.SqlClient 什么都一样. 
    估计 System.Data.MySqlClient 已经自动帮我们把byte[] 转换了
    不过没试过.楼主好运
    .
      

  12.   

    用MySQL的dll啊,很好用,很简单!!
    http://dev.mysql.com/downloads/connector/net/6.1.html
      

  13.   

    我在C++CLI 中用过,和C#仅仅表现形式稍有差别,你很容易看懂。自己加上try catch
    直接用OdbcConnection 用其它上层数据库连接类的也有,如果需要可以给你。int UpdateBlob(OdbcConnection^ m_dbConn, String^ FileName,int docID)
    {
    //you should put following code into try catch
    //support you have a table with 2 columns: docID and imgfile//read image file
    FileStream^ fs = gcnew FileStream(FileName, FileMode::Open, FileAccess::Read);
    int  FileSize = (int)fs->Length;
    array<Byte>^ rawData = gcnew array<Byte>(FileSize);
    fs->Read(rawData, 0, FileSize);
    fs->Close();

    //make sql  
    String^ sql = String::Format("UPDATE table1 VALUES({0},?)",docID);
    OdbcCommand^ cmd = gcnew OdbcCommand(sql,m_dbConn);
    cmd->Parameters->Add("imgfile",OdbcType::Binary,FileSize,"imgfile")->Value = rawData;//do update now
    ret = cmd->ExecuteNonQuery();
    return ret;
    }
      

  14.   

    这是从文件中读取更新SQL中的参数
      

  15.   

    http://blog.csdn.net/sciland/archive/2009/03/25/4023679.aspx
    我以前在c#中连接过MySQL,上面的链接有介绍;像 string sql = "update table_name set col_name='" + values + "'where col2='" + values2 + "'";完成后就执行 RunSqlDatacmd(sql)就好了,RunSqlDatacmd(sql)代码如下:        public static long RunSqlDatacmd(string sql)    //sql语句执行成员
            {
                MySqlConnection dbconn = new MySqlConnection("Database='Online';Data Source='localhost';User Id='root';Password='123456';charset=utf8");
                MySqlCommand cmd = dbconn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sql;
                long ret = 0;
                try
                {
                    if (cmd.Connection.State == ConnectionState.Broken)
                    {
                        cmd.Connection.Close();
                        cmd.Connection.Open();
                    }
                    else if (cmd.Connection.State == ConnectionState.Closed)
                    {
                        cmd.Connection.Open();
                    }
                    // else if (cmd.Connection.State == ConnectionState.Open)
                    // {
                    ret = cmd.ExecuteNonQuery();
                    // }
                    //else
                    // {
                    //     ret = -102;
                    // }
                }
                catch (Exception ex)
                {
                    string m = ex.Message;
                    ret = -5;
                }
                cmd.Dispose();
                dbconn.Close();
                return ret;
            }     }
    }
      

  16.   

    没啥本质的区别,mysql需要下载dll,MySqlConnection 就可以了。老紫竹我想转JAVA。请问.net三年经验转java容易么。我用C#写过大型框架。
      

  17.   

    public void SaveImg(string Pid,string sysname , string username,string Ip,
                string title ,string wjtype , int size, byte[] buffByte)
            {
                string comm = "insert s_pic(Pid,sysname,username,IP,title,wjtype,size,pic,others,queryers,deleters)" +
                    " values({0},'{1}','{2}','{3}','{4}','{5}',{6},@img,'','','')";
                // @"Insert into table1(img,name) values(@img,@name)";
                SqlCommand  sqlCommand1 = new System.Data.SqlClient.SqlCommand();
                sqlCommand1.CommandType = System.Data.CommandType.Text;
                sqlCommand1.CommandText = string.Format( comm ,Pid ,sysname ,username ,Ip ,title ,wjtype ,size ) ;
                sqlCommand1.Connection = Connection;
                //创建Parameter
                sqlCommand1.Parameters.Add("@img", System.Data.SqlDbType.Image);
                sqlCommand1.Parameters[0].Value = buffByte;
                try
                {
                    Connection.Open();
                    sqlCommand1.ExecuteNonQuery();
                    m_bln = true;
                }
                catch { m_bln = false; }
                finally
                {
                    Connection.Close();
                    Connection.Dispose();
                }
                buffByte = null;
            }
      

  18.   


    JAVA入门很容易,深入很难
    .net 入门很容易,深入也比较容易精通的都是思想,不是工具。
      

  19.   

    学习c#和Mysql数据库
      还是顶哈。。
      

  20.   

    全国最大的护肤品卖场http://p.alimama.com/cpsglist.php?q=&u=561352&pid=mm_13861612_0_0&d=1091876273,1083861714,1395779729,77832854,1550437524,1098267920,1086340700,1695295499,1465722367,2055893799,1343465228,203545090,1883775681,67027742,1649895732,1936615803,1855579482,1898837250,1315394694,1402554411&str=1251381951&m=33
      

  21.   

    http://p.alimama.com/cpsglist.php?q=&u=561352&pid=mm_13861612_0_0&d=1091876273,1083861714,1395779729,77832854,1550437524,1098267920,1086340700,1695295499,1465722367,2055893799,1343465228,203545090,1883775681,67027742,1649895732,1936615803,1855579482,1898837250,1315394694,1402554411&str=1251381951&m=33">全国最大的护肤品卖场
      

  22.   

    .net不像java那样 把不同的数据库连接 封装到同一个类中java是Connection.net中要根据不同类数据使用不同的连接类(包括其数据库操作类也不一样,统称为:.net数据提供程序)
      

  23.   

     int xA_ = this.lblLTA.Location.X;
                int yA_ = this.lblLTA.Location.Y;
                int hA_ = this.lblLTA.Height;
                this.lblLTA.Tag = this.lblLTA_.Tag.ToString();
                int A_ = Convert.ToInt32(this.lblLTA_.Tag) * 3;
                this.lblLTA.Location = new Point(xA_, yA_ - A_);
                this.lblLTA.Height = hA_ + A_;
                this.lblLTA.Location = new Point(xA_, yA_ - A_);
                this.lblLTA.Height = hA_ + A_;
      

  24.   

    顶、 
    http://www.xinkeor.cn/?11604-1.html
      

  25.   

    顶、 
    http://www.xinkeor.cn/?11604-1.html