Click here to Skip to main content
15,886,518 members
Home / Discussions / Database
   

Database

 
AnswerRe: checking the fieldname in the table Pin
PIEBALDconsult13-Jun-11 14:48
mvePIEBALDconsult13-Jun-11 14:48 
AnswerRe: checking the fieldname in the table Pin
Mohamad Kaifi13-Jun-11 23:53
Mohamad Kaifi13-Jun-11 23:53 
GeneralRe: checking the fieldname in the table Pin
PIEBALDconsult14-Jun-11 2:53
mvePIEBALDconsult14-Jun-11 2:53 
GeneralRe: checking the fieldname in the table Pin
Dhyanga14-Jun-11 3:10
Dhyanga14-Jun-11 3:10 
AnswerRe: checking the fieldname in the table Pin
Simon_Whale14-Jun-11 3:04
Simon_Whale14-Jun-11 3:04 
GeneralRe: checking the fieldname in the table Pin
Dhyanga14-Jun-11 3:12
Dhyanga14-Jun-11 3:12 
QuestionComparing Table Entries Using C# and MS Access Pin
VonHagNDaz13-Jun-11 8:16
VonHagNDaz13-Jun-11 8:16 
AnswerRe: Comparing Table Entries Using C# and MS Access Pin
Johan Hakkesteegt27-Jun-11 0:06
Johan Hakkesteegt27-Jun-11 0:06 
Okay, so that's just a lot of text, and the question seems to be drowning in it. That's why nobody is answering I guess.

So I will answer what I am guessing is the core question here:
The basic idea is to get the list with sql, compare stuff and change values with C# and finally update these values with sql.
So first of all you'll want to use an UPDATE query instead of removing and reinserting each row.

//So this indeed gets you the list.
OleDbCommand dbCommand = new OleDbCommand("SELECT * FROM tblUsers", this._dbConnection);

//Your reader then loops through the rows and you compare and check stuff

//Then you apply some logic, and determine what the values should be

//And then somewhere at the end of your reader loop you actually update your database like so:
OleDbCommand dbUpdateCommand = new OleDbCommand("UPDATE tblUsers " _
                                                "SET FieldOne = @ParameterOne " _
                                                ", FieldTwo = @ParameterTwo " _
                                                "WHERE KeyField = @ParameterThree ", this._dbConnection);
dbUpdateCommand.Parameters.Add("@ParameterOne", _
                            SqlDbType.NVarChar).Value = SomeVariableHoldingTheValueInQuestion;
dbUpdateCommand.ExecuteNonQuery;


N.B. You may have to use a second connection for the update (I don't remember for sure)...
N.B. I used the syntax for MS SQL. You may have to adapt it to MS Access syntax, as it often uses its own slightly different version. You can check this by building a simple update query with the MS Access Query wizard / query builder.

A coding tip: try to avoid using index numbers for database fields in your code:
currentUser.Name = userData["UserName"].ToString();
is better than
currentUser.Name = userData[0].ToString();
because otherwise when you make a change in your database table or in the query, that will change the order of the fields, and then your code will run amok. Or you will be forced to edit your code all the time, and figure out which field is which index number over and over.
My advice is free, and you may get what you paid for.

QuestionHow to remove column "rowguid" from table in SQL server 2008? Pin
Hy Chanhan13-Jun-11 5:53
professionalHy Chanhan13-Jun-11 5:53 
AnswerRe: How to remove column "rowguid" from table in SQL server 2008? Pin
Hy Chanhan13-Jun-11 17:48
professionalHy Chanhan13-Jun-11 17:48 
QuestionRow by row error handling in Table value parameter in SQL 2008 Pin
Lijo Rajan13-Jun-11 5:22
Lijo Rajan13-Jun-11 5:22 
Question[SSIS 2008] - Global transformation method for GUID fields Pin
phil.o13-Jun-11 0:45
professionalphil.o13-Jun-11 0:45 
QuestionRecordset Seek - multiple fields Pin
john john mackey10-Jun-11 13:35
john john mackey10-Jun-11 13:35 
AnswerRe: Recordset Seek - multiple fields Pin
Eddy Vluggen11-Jun-11 1:00
professionalEddy Vluggen11-Jun-11 1:00 
Questionmoving column in sql Pin
Milad.Biroonvand10-Jun-11 9:32
Milad.Biroonvand10-Jun-11 9:32 
AnswerRe: moving column in sql Pin
GenJerDan10-Jun-11 11:21
GenJerDan10-Jun-11 11:21 
AnswerRe: moving column in sql Pin
David Skelly12-Jun-11 22:40
David Skelly12-Jun-11 22:40 
GeneralRe: moving column in sql Pin
Milad.Biroonvand13-Jun-11 7:50
Milad.Biroonvand13-Jun-11 7:50 
AnswerRe: moving column in sql Pin
thatraja13-Jun-11 0:03
professionalthatraja13-Jun-11 0:03 
GeneralRe: moving column in sql Pin
Milad.Biroonvand13-Jun-11 7:53
Milad.Biroonvand13-Jun-11 7:53 
GeneralRe: moving column in sql Pin
Pete O'Hanlon13-Jun-11 9:01
mvePete O'Hanlon13-Jun-11 9:01 
QuestionGet Percentages Of Rows With Date In Them - Grouped Pin
Kevin Marois10-Jun-11 5:48
professionalKevin Marois10-Jun-11 5:48 
QuestionSQL Function problem Pin
Etienne_12310-Jun-11 0:07
Etienne_12310-Jun-11 0:07 
AnswerRe: SQL Function problem Pin
PIEBALDconsult10-Jun-11 2:47
mvePIEBALDconsult10-Jun-11 2:47 
AnswerRe: SQL Function problem Pin
Eddy Vluggen10-Jun-11 6:18
professionalEddy Vluggen10-Jun-11 6:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.