zoukankan      html  css  js  c++  java
  • 初学c# -- 学习笔记(9) 关于SQL2008

    在做一个局域网的类似网盘的学习练习,服务端差不多了,在改bug。用vlc的dll做的全格式视频、音频预览在线播放下载等等。

    在做服务端也遇到了一些问题,走了好多弯路。

    开始把上传的视频、音频、图像、文件等已二进制存放到数据库里,播放二进制流,做成了,结果。。数据库那个慢啊,最后放本地硬盘了。

    在服务端数据库文件记录管理批量处理上又学了一些,主要靠存储过程来批量处理记录:

    建立2个函数

    USE [Transmis]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER function [dbo].[Get_StrArrayLength]
    (
      @str varchar(1024),
      @split varchar(10) 
    )
    returns int
    as
    begin
      declare @location int
      declare @start int
      declare @length int
      set @str=ltrim(rtrim(@str))
      set @location=charindex(@split,@str)
      set @length=1
      while @location<>0
      begin
        set @start=@location+1
        set @location=charindex(@split,@str,@start)
        set @length=@length+1
      end
      return @length
    end
    USE [Transmis]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER function [dbo].[Get_StrArrayStrOfIndex]
    (
      @str varchar(1024),  
      @split varchar(10),  
      @index int 
    )
    returns varchar(1024)
    as
    begin
      declare @location int
      declare @start int
      declare @next int
      declare @seed int
      set @str=ltrim(rtrim(@str))
      set @start=1
      set @next=1
      set @seed=len(@split)
      set @location=charindex(@split,@str)
      while @location<>0 and @index>@next
      begin
        set @start=@location+@seed
        set @location=charindex(@split,@str,@start)
        set @next=@next+1
      end
      if @location =0 select @location =len(@str)+1 
      return substring(@str,@start,@location-@start)
    end


    再写存储过程

    USE [Transmis]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[Files_Delete]  
    @s_id varchar(1024)
    as
    declare @next int  
    set @next=1
    while @next<=dbo.Get_StrArrayLength(@s_id,'$')
    begin
      DELETE FROM Trans_File WHERE id = dbo.Get_StrArrayStrOfIndex(@s_id,'$',@next)
      set @next=@next+1
    end

    在C#里面传递参数调用就可以批量删除了

    if (form6.DialogResult == DialogResult.OK)
                    {
                        for (int i = 0; i < das_cont.Rows.Count; i++)
                        {
                            if (conter_Panel.Controls[i].Tag.ToString() != "Normal")
                            {
                                del_id += conter_Panel.Controls[i].Tag.ToString() + "$";
                                string extname = Path.GetExtension(conter_Panel.Controls[i].Name);
    
                                if (String.Compare(extname, ".mp3", true) == 0) //删除强制的mp3音频文件
                                {
                                    dirpath = @"audio";
                                }
                                else //删除强制的mp4视频文件
                                if (String.Compare(extname, ".mp4", true) == 0)
                                {
                                    dirpath = @"video";
                                }
                                else。。。。。。。。。。。。。。。。。。。
    ........................................................................
    .......................................................................
    File.Delete(del_path); /* try { File.Delete(del_path); } catch { } */ } } if (del_id != "") { SqlCommand com = new SqlCommand(); com.Connection = Conn; com.CommandType = CommandType.StoredProcedure; com.CommandText = "Files_Delete"; com.Parameters.Add("@s_id", SqlDbType.VarChar, 8000); com.Parameters[0].Value = del_id; com.ExecuteNonQuery(); AddFiles("id"); }


    就是把文件名生成字符串用符号隔开,传递到存储过程。

    挺好用,修改一下,批量插入更新等批量操作都可以了。

    这个学习练习用64位写的,改32位有问题了,在处理下。

  • 相关阅读:
    2021NUAA暑假集训 Day3 题解
    2021NUAA暑假集训 Day2 题解
    2021NUAA暑期模拟赛部分题解
    CodeForces 1038D Slime
    UVA 11149 Power of Matrix
    UVA 10655 Contemplation! Algebra
    UVA 10689 Yet another Number Sequence
    HDU 4549 M斐波那契数列
    HDU 4990 Reading comprehension
    CodeForces 450B Jzzhu and Sequences
  • 原文地址:https://www.cnblogs.com/qiaoke/p/6265619.html
Copyright © 2011-2022 走看看