Click here to Skip to main content
15,889,732 members
Home / Discussions / C#
   

C#

 
AnswerRe: data synchronization between two client machine over the internet by Webservice? Pin
Dave Kreskowiak31-Jul-09 4:51
mveDave Kreskowiak31-Jul-09 4:51 
QuestionHow to know toolbar got clicked through a BHO (C#)? Pin
svt gdwl31-Jul-09 0:05
svt gdwl31-Jul-09 0:05 
Questioncode for updating datatable. Pin
Omar Akhtar Sheikh30-Jul-09 23:46
Omar Akhtar Sheikh30-Jul-09 23:46 
AnswerRe: code for updating datatable. Pin
Not Active30-Jul-09 23:51
mentorNot Active30-Jul-09 23:51 
JokeRe: code for updating datatable. Pin
Nagy Vilmos31-Jul-09 0:01
professionalNagy Vilmos31-Jul-09 0:01 
GeneralRe: code for updating datatable. Pin
PIEBALDconsult31-Jul-09 4:55
mvePIEBALDconsult31-Jul-09 4:55 
AnswerRe: code for updating datatable. Pin
PIEBALDconsult31-Jul-09 4:54
mvePIEBALDconsult31-Jul-09 4:54 
AnswerRe: code for updating datatable. Pin
Adam R Harris31-Jul-09 8:05
Adam R Harris31-Jul-09 8:05 
Your using your DataAdapter all wrong.

It should be declared outside the scope of the GetCustomers(), so it can be accessed by all the other functions, and you should be using it to Create/Read/Updated/Delete.

How To Update a SQL Server Database by Using the SqlDataAdapter Object in Visual C# .NET[^]

NOTE: the code below has not been tested / probably wont compile because i cant spell

your code should look something like this;
// Dont know if this is going to be accessed outside of the class
// If so you might want to make a wrapper property for it
private SqlDataAdapter da;
// Should contain your data
private DataSet ds;

..... somewhere in your initialization code .....
da = new SqlDataAdapter("SELECT * FROM Customer_2", [YourConnectionString]);
da.UpdateCommand = [your update command];
da.DeleteCommand = [your delete command];
da.InsertCommand = [your insert command];

// dont return anything here, just fill the dataset
public void GetCustomers()
{
         da.Fill(ds);
}

// Saves all the changes to the database
public void SaveChanges()
{
         da.Update(ds, "[your table name]");
         // Accept the changes in the dataset
         ds.AcceptChanges();
}


Then all you need to do is Create/Update/Delete all the rows you want in the DataSet, just make sure you call SaveChanges().

Thats how your supposed to use the DataAdapters.

But if you still want to use it in the way that you are using it, your going to have to loop through all the rows in the DataTable and check if their RowState == DataRowState.Changed (i think, could be updated), then just run your update command against SQL.

If at first you don't succeed ... post it on The Code Project and Pray.

GeneralRe: code for updating datatable. Pin
Omar Akhtar Sheikh31-Jul-09 8:27
Omar Akhtar Sheikh31-Jul-09 8:27 
GeneralRe: code for updating datatable. Pin
Adam R Harris31-Jul-09 9:16
Adam R Harris31-Jul-09 9:16 
General[Message Deleted] Pin
Omar Akhtar Sheikh31-Jul-09 11:56
Omar Akhtar Sheikh31-Jul-09 11:56 
GeneralRe: code for updating datatable. Pin
Adam R Harris31-Jul-09 12:14
Adam R Harris31-Jul-09 12:14 
QuestionProblem in Filter Grid Pin
SwastikInfosystems30-Jul-09 23:29
SwastikInfosystems30-Jul-09 23:29 
AnswerRe: Problem in Filter Grid Pin
OriginalGriff30-Jul-09 23:54
mveOriginalGriff30-Jul-09 23:54 
AnswerRe: Problem in Filter Grid Pin
stancrm30-Jul-09 23:55
stancrm30-Jul-09 23:55 
AnswerRe: Problem in Filter Grid Pin
Nagy Vilmos30-Jul-09 23:59
professionalNagy Vilmos30-Jul-09 23:59 
QuestionProblem in Filter Grid Pin
SwastikInfosystems30-Jul-09 23:17
SwastikInfosystems30-Jul-09 23:17 
AnswerRe: Problem in Filter Grid Pin
Vimalsoft(Pty) Ltd31-Jul-09 0:06
professionalVimalsoft(Pty) Ltd31-Jul-09 0:06 
Questiongive me a code for disable keyboard functions this project............ [modified] Pin
Member 423560130-Jul-09 22:28
Member 423560130-Jul-09 22:28 
AnswerRe: Add to disable keyboard functions this project............ Pin
OriginalGriff30-Jul-09 23:16
mveOriginalGriff30-Jul-09 23:16 
GeneralRe: Add to disable keyboard functions this project............ Pin
Luc Pattyn30-Jul-09 23:36
sitebuilderLuc Pattyn30-Jul-09 23:36 
GeneralRe: Add to disable keyboard functions this project............ Pin
Baeltazor31-Jul-09 7:17
Baeltazor31-Jul-09 7:17 
GeneralRe: Add to disable keyboard functions this project............ Pin
OriginalGriff31-Jul-09 8:12
mveOriginalGriff31-Jul-09 8:12 
GeneralRe: <blockquote class="FQ"><div class="FQA">OriginalGriff wrote:</div>Fraid so...Umpteen[^]</blockquote> Pin
Baeltazor31-Jul-09 10:01
Baeltazor31-Jul-09 10:01 
Questionusing statement Vs Dispose/Finalize pattern Pin
Cracked-Down30-Jul-09 21:28
Cracked-Down30-Jul-09 21:28 

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.