问题描述
您好,
我有一个文本文件,其内容如下:
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
推荐答案
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)中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!