zoukankan      html  css  js  c++  java
  • 操作sql2000中的text,image字段类型.

    在存贮过程里读写text,要用到READTEXT  UPDATETEXT  WRITETEXT  进行操作.

    在C#中,用select text from table 是可以直接取到值的.

    在做更新,新增操作时,用@text传text的值,也能正常赋值.

    text类型直接赋string

    image类型用byte[]

     insert:

    string strSql = "INSERT INTO [dbo].[Tableimg]( [img]) VALUES(@img) ";
    using (System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(CommConfig.InfodbConnectstring))
    {
        System.Data.SqlClient.SqlCommand myCommand 
    = new System.Data.SqlClient.SqlCommand(strSql, myConnection);
        myConnection.Open();
       
    string str = new string('X'100000);
       
    byte[] bytes = System.Text.Encoding.Default.GetBytes(str.ToCharArray());

        SqlParameter sp 
    = new SqlParameter("@img", SqlDbType.Image);
        sp.Value 
    = bytes;

        myCommand.Parameters.Add(sp);
        
    int re = myCommand.ExecuteNonQuery();

        myCommand.Dispose();
        myConnection.Close();
    }

    select:

    string strSql = "SELECT [id], [img] FROM [dbo].[Tableimg] where id = 1 ";

    using (System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(CommConfig.InfodbConnectstring))
    {
        System.Data.SqlClient.SqlCommand myCommand 
    = new System.Data.SqlClient.SqlCommand(strSql, myConnection);
        myConnection.Open();

        SqlDataReader dr 
    = myCommand.ExecuteReader();
        
    while (dr.Read())
        
    {
            Byte[] bytes 
    = (byte[])dr[1];
            
    string str = System.Text.Encoding.Default.GetString(bytes);
        }

        
        myCommand.Dispose();
        myConnection.Close();
    }
  • 相关阅读:
    JavaScript语言和jQuery技术1
    JSP2
    JavaScript语言和jQuery技术2
    MYSQL2
    JSP1
    JSP5
    JSP3
    Spring框架
    JSP4
    MYSQL3(查询)
  • 原文地址:https://www.cnblogs.com/greatqn/p/637117.html
Copyright © 2011-2022 走看看