Link to home
Start Free TrialLog in
Avatar of R8VI
R8VI

asked on

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

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
Avatar of R8VI
R8VI

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of R8VI
R8VI

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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