如何检查文本文件的内容是否在数据库(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?