Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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:

C#
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?
 
Share this answer
 
Comments
DEbopm 5-Jan-14 22:45pm    
hello db7uk .. U set the value as 00000570642 . but let me tell you on e thing it should not be a static value. value could be different one in each line .

09^^^O^4345^^^^^^^2^9994^443524^00000570642^^CAD
09^^^P^7101^^^^^^^2^9994^443524^00000570643^^CAD
09^^^Q^7101^^^^^^^1^9994^443524^00000570644^^CAD

This is the actual text file where the digits are different and multiple rows are there in the text file. So we need to do it position basis and not hard coding the value.
DEbopm 5-Jan-14 22:47pm    
and one more thing - I need to delete the row from text file if it is present and not from sql table.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900