Click here to Skip to main content
15,615,668 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
The idea is that i`ve got a database and and application, the application loads data into the database but the problem is that I often get duplicate values, so before i added the values to the database i want to browse all records in the DB and see if any record matches the line i want to add. I want to compare theese 3 strings with the first 3 collumns of every row in my databale. How do I do that?

string third = array[0];
string first = array[1];
string second = array[2];

string vudz = "SELECT name,lastname,dob FROM players";

NpgsqlDataAdapter npgsqldataadapter1 = new NpgsqlDataAdapter(new NpgsqlCommand(vudz, conection));
DataRow drow = datatable11.NewRow();

/Edit Code Block corrected by Jibesh /Edit
Updated 10-Jan-13 7:54am
Jibesh 10-Jan-13 14:00pm    
Your question and your sample doesnt match. but with the information you can try select statement with where query. can you also elaborate your question
[no name] 10-Jan-13 14:17pm    
If the three rows match what do you want to do with the record you are inserting? It might be easier to do this at the database level

1 solution

Why not just run a query:

using (SqlConnection con = new SqlConnection(strConnect))
    using (SqlCommand com = new SqlCommand("SELECT COUNT(*) FROM players WHERE [name]=@AR1 AND lastname=@AR2 AND dob=@AR3", con))
        com.Parameters.AddWithValue("@AR1", first);
        com.Parameters.AddWithValue("@AR2", second);
        com.Parameters.AddWithValue("@AR3", third);
        if( com.ExecuteScalar > 0)
            // It exists already
Share this answer

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