Torrey’s Blog

My Application Development Ramblings

It’s not that peachy Microsoft!

May29

In my last post I blogged about n-tier development and updating a dataset through a web service. Later that night I found the link from Microsoft showing how to update data through a web service. Well, I tried it out the next morning…Life is not as simple as they make it look! Trying to update that way ended up making my web service complain about the dataset not being the correct type, so I ended up using my first method. I also ended up adding a little extra flavor to the update webservice method so it’ll handle inserts, deletions, and updates. If I get the chance today I’ll post up the source code for that on my blog and also the snippets section of this website.

Happy coding, it’s almost the weekend!

Updating a DataSet Through a Webservice

May27

Alright, so I’ve been racking my brain around this whole n-tier architecture and started converting one client’s software to this type of solution. When it comes to creating the various layers and web service that just pulls data it’s easy as pie. Updating a DataSet through a data access layer that communicates to a web service is a whole other story. Here’s a quick overview of how I achieved the update.

1) The smart client issued an update event that called the DAL (date access layer) update.

2) The DAL passes the DataSet to the web service. Keep in mind during the first two steps I used the generic type DataSet. The smart client doesn’t actually contain the DataSet types that are stored in regular applications that could made the update a whole lot easier, that’s the reason why I’m using the generic DataSet type.

3) The webservice uses the method below for updating the DataSet. The more reference material I read lately, I may end up changing the update method, I believe that I’m doing it partially incorrect even though it works perfectly.

         [WebMethod(Description = “Updates the edited Job Log row.”)]          public String update_tblJobLog(DataSet tblJobLogDS)          {              DataSets.tblJobLogDataSetTableAdapters.tblJobLogTableAdapter tblJobLogTableAdapter = new Company_Webservice.DataSets.tblJobLogDataSetTableAdapters.tblJobLogTableAdapter();              Company_Webservice.DataSets.tblJobLogDataSet typedtblJobLogDS = new Company_Webservice.DataSets.tblJobLogDataSet();              typedtblJobLogDS.Load(tblJobLogDS.Tables[“tblJobLog”].CreateDataReader(), LoadOption.OverwriteChanges,                  typedtblJobLogDS.tblJobLog);              typedtblJobLogDS.tblJobLog.Rows[0].SetModified();              try              {                  tblJobLogTableAdapter.Update(typedtblJobLogDS);                  return “Success”;              }              catch (Exception ex)              {                  return ex.Message;              }          }  

There’s actually a way I can just pass the rows I need by using the GetChanges method, then cycle through the loaded rows to update the RowState. This style of programming definately has its pros and cons, but I think in the long run it’s going to work wonders for scalability since this particular client is expanding like their is no tomorrow.

[edit]

Just googled the magic phrase and found out Microsoft actually has a code snippet that shows an easy way to update a dataset through a webservice. It figures I nearly make my brain bleed trying to get the update to process earlier, and Microsoft has the solution sitting right there. Sometimes all it takes is the magic search phrase…

[WebMethod]         public DataSet GetCustomers()         {             SqlConnection con = new SqlConnection(“server=servername;uid=login;  pwd=password;database=northwind”);             SqlDataAdapter daCust = new SqlDataAdapter(“Select * From Customers”, con);             DataSet ds = new DataSet();             daCust.Fill(ds, “Cust”);             return ds;         }       [WebMethod]         public DataSet UpdateCustomers(DataSet ds)         {              SqlConnection con = new SqlConnection(“server=servername;uid=login;  pwd=password;database=northwind”);              SqlDataAdapter daCust = new SqlDataAdapter(“Select * From Customers”, con);              SqlCommandBuilder cbCust = new SqlCommandBuilder(daCust);              daCust.Update(ds, “Cust”);              return ds;          }
   

Beginning N-Tier Development

May22

Within the past week or so I’ve started studying up on N-Tier applications since I’ve been experiencing overload on one particular client expanding faster than I can keep up with application maintenance. This client has grown so much in the past 2 months that I have been working almost non-stop to develop a solution that works with their business. Now that I understand what N-Tier is and means, I really feel silly for not looking into that sooner. You’ll read that it’s mainly for large scale applications, but there is actually a need for such a architecture in small business too. From this point on I plan on creating layers for every project I work on. It makes perfect sense and will ease future projects because I can reuse the various layers.

I would keep typing more, but I’m half asleep right now, so I’ll try to catch up with more posts tomorrow. Goodnight!