字符串截取 数据库里某个字段并重新保存到那个字段 C#

 1 using System;
 2 using System.Collections;
 3 using System.Configuration;
 4 using System.Data;
 5 using System.Linq;
 6 using System.Web;
 7 using System.Web.Security;
 8 using System.Web.UI;
 9 using System.Web.UI.HtmlControls;
10 using System.Web.UI.WebControls;
11 using System.Web.UI.WebControls.WebParts;
12 using System.Xml.Linq;
13 using System.Data.SqlClient;
14 using SchoolCrm.DBUtility;
15 
16 namespace SchoolCrm.Web
17 {
18     public partial class WebForm1 : System.Web.UI.Page
19     {
20         protected void Page_Load(object sender, EventArgs e)
21         {
22 
23 
24         }
25 
26         protected void Button1_Click(object sender, EventArgs e)
27         {
28             //string str =@"E:\文档\查询系统\源码\SchoolCrm\Admin\AnLi_Schoolhttp://www.cnblogs.com/../AnLiFile\20121224634919572560504783_安一娜华大I-20.pdf";
29 
30             int count = 1;
31             DataSet ds = DbHelperSQL.Query(" SELECT  f.* FROM AnLi_ApplySchoolFiles f  ");
32             foreach (DataRow item in ds.Tables[0].Rows)
33             {
34                 string str = item["FilesName"].ToString();
35                 string str2 = str.Substring(str.LastIndexOf("\\") + 1);
36                 SqlParameter[] parameters = {
37                     new SqlParameter("@FilesName1", SqlDbType.NVarChar),
38                     new SqlParameter("@FilesId", SqlDbType.NVarChar)};
39                 parameters[0].Value = str2;
40                 parameters[1].Value = item["FilesId"].ToString();
41                 string sqlstr = " update AnLi_ApplySchoolFiles  set FilesName=@FilesName1  where FilesId=@FilesId ";
42                 int rows = DbHelperSQL.ExecuteSql(sqlstr, parameters);
43                 if (rows > 0)
44                 {
45                     count++;
46                 }
47             }
48             Response.Write(" 成功" + count);
49 
50         }
51 
52 
53     }
54 }
原文地址:https://www.cnblogs.com/chenghu/p/2835407.html