We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Compare database results on the fly visual c#, asp.net

R8VI
R8VI asked
on
Medium Priority
569 Views
Last Modified: 2013-12-17
Hi,

What I want to do is get all the results from the database of a particular row and compare them to a string if the string does not match any row then insert.
I know how to establish a connection and get the results

can someone provide some code examples

Please help

Thanks,

R8VI
Comment
Watch Question

Author

Commented:
right,

I have this so far

 ArrayList GetDat = new ArrayList();

                                SqlConnection oConnecttoNwsCategories = new SqlConnection(ConfigurationManager.ConnectionStrings["Cs"].ConnectionString);


                                oConCategories.Open();


                                SqlCommand EverythinginPageUrls = new SqlCommand("sp", oConCategories);
                                EverythinginPageUrls.CommandType = CommandType.StoredProcedure;
                                EverythinginPageUrls.ExecuteNonQuery();
                                SqlDataReader rdrEnPageUrls= EverythinginPageUrls.ExecuteReader();

                                while (rdrEnPageUrls.Read())
                                {
                                    GetallRFromDatabase = rdrEvery["rerl"].ToString();

                                   
                                }

but get an error on  GetallRFromDatabase = rdrEvery["rerl"].ToString();

thanks,

R8VI


what error are you getting?
Commented:
i sorted that now lol so i have this so far


ArrayList GetDat = new ArrayList();

                                SqlConnection oConnecttoNwsCategories = new SqlConnection(ConfigurationManager.ConnectionStrings["Cs"].ConnectionString);


                                oConCategories.Open();


                                SqlCommand EverythinginPageUrls = new SqlCommand("sp", oConCategories);
                                EverythinginPageUrls.CommandType = CommandType.StoredProcedure;
                                EverythinginPageUrls.ExecuteNonQuery();
                                SqlDataReader rdrEnPageUrls= EverythinginPageUrls.ExecuteReader();

                                while (rdrEnPageUrls.Read())
                                {
                                    string requrls = rdrEverytPageUrls["retedurl"].ToString();
                                GetallRFromDatabase .Add(requrls );

                                   

                                   
                                }
                       for (int i=0; i<GetallRFromDatabase .count; i++)
                     {
                          string variabletocompare
                          here i want to compare this variable with the results that are stored in            
                         GetallRFromDatabase list and then if its in there do nothing else insert into the DB inserting is no problem comparing is the bit i am stuck on
                     }


Thanks,

R8VI

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Anurag ThakurTechnical Manager

Commented:
The check you are trying to do is quite simple
i will give you the logic to do in the stored procedure

in the sp first check for if the record you are trying to insert exists or not
let the variable in the db is @Name

If Exists (Select 1 From TableName Where Name = @Name)
Begin
   // update the existing record
End
Else
Begin
   //Insert a new record
End

>> you said you are getting error on this line  GetallRFromDatabase = rdrEvery["rerl"].ToString();
but what is the type of GetallRFromDatabase
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.