如何检查文本文件的内容是否在数据库(SQL Server)中 [英] How do I check if the content of text file is in Database( SQL Server) or not

查看:84
本文介绍了如何检查文本文件的内容是否在数据库(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)中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆