如何检查文本文件的内容是否在数据库(SQL Server)中

编程入门 行业动态 更新时间:2024-10-27 06:23:49
本文介绍了如何检查文本文件的内容是否在数据库(SQL Server)中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我有一个文本文件,其内容如下: 09 ^^^ O ^ 4345 ^^^^^^^ 2 ^ 9994 ^ 443524 ^ 00000570642 ^^ CAD 09 ^^^ P ^ 7101 ^^^^^^^ 2 ^ 9994 ^ 443524 ^ 00000570642 ^^ CAD 09 ^^^ Q ^ 7101 ^^^^^^^ 1 ^ 9994 ^ 443524 ^ 00000570642 ^^ CAD 我想通过一些select sql查询检查内容00000570642是否在DB中。 如果这将出现在DB中,那么我需要删除文本文件中的完整行。 请告诉我使用CSharp控制台应用程序和sql连接执行此操作的方式和代码

Hello , I have a text file and its content is like this : 09^^^O^4345^^^^^^^2^9994^443524^00000570642^^CAD 09^^^P^7101^^^^^^^2^9994^443524^00000570642^^CAD 09^^^Q^7101^^^^^^^1^9994^443524^00000570642^^CAD I want to check if the content "00000570642" is in DB by some select sql query. And if that will present in DB then I need to delete the full rows from text file. Kindly tell me the way and code of doing this using CSharp console Application and sql connection

推荐答案

使用sql命令和删除语句相当容易。 假设您的文本文件已插入SQL数据库。您可以执行以下操作: This is fairly easy to do with an sql command and a delete statement. Assuming your text file is inserted into a SQL database. You could do something like: using (var sc = new SqlConnection(ConnectionString)) using (var cmd = sc.CreateCommand()) { string value = "%^00000570642^%" sc.Open(); cmd.CommandText = "DELETE FROM table WHERE textField like @value"; cmd.Parameters.AddWithValue("@value", value); cmd.ExecuteNonQuery(); }

这就是你所追求的吗?

Is this what you were after?

更多推荐

如何检查文本文件的内容是否在数据库(SQL Server)中

本文发布于:2023-11-07 01:16:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565154.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本文件   数据库   内容   Server   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!