January 2006 - Posts

I had a quick requirement to bind a grid from data and do some CRUD operations. Since it was small app for my friend, didn’t consider anything about architectural design. He just wanted some couple of forms which has datagrid and to do some filtering and CRUD stuff.

            I never worked with the datagrid visual binding stuff (Drag & Drop Adapters, source .etc), not only VS 2003, but also VS 2005.  I had to do that app quick & I knew if I start to use custom objects and collections it will take time. So I decided to use datasets instead. Even if I never use designer for databinding, it was cool.. Did the job in ½ hour (3 forms with Show/Add/Edit/Delete/Search)... Its was VS 2005 , but still I found my self really comfortable with it. We can create a sproc from the designer or we can use the existing ones. When I open the Typed Dataset in the designer, it shows all the methods in the dataAdapter, so that I can add/edit/delete new methods according to my requirement.

 I’ll quickly show you how to Bind/Update/Search the data.

 Drag & Drop DataGridView control to the form. Click on the smart tag and Add a new DataSource. (ConnectionString is saving in the appConfig file. That’s really cool; I don’t think in VS 2003 we had that option.)

  1. After selecting the datasource , just select the option you want to do, View/Update/Delete etc. And then you will get a query builder. Build your query. Then finish the task.
  2. If you go to Form_Load event now, you can see vs automatically fill the dataset from the adapter for you. So no coding at all. Run it and See.
  3. To update the datagridview, all you have to do it, in the updatebuton_click event call the Update method in the Adapter by passing the DataSet.
  4. If you want to search for some item and if you want to bind the search item in the same grid, all you have to do is open the DataSet in the designer. And you will see the Adapter methods. Right click on that and Add Query,  then you can select the Stored Procedure, and the it will automatically create a method for us by passing correct parameters which is taken from the Stored Proc.
  5. To search, in the SearchButton_click event, simply call the adapter method (which we have created) by passing the correct parameters.

 There are many things you can with it. I just wanna give you a small preview of this. If you ever wanted to do small app in no time go for this. It’s really cool!

 

Posted by Ludmal De Silva | with no comments
My article about WSAT(Web Site Administration tool) is published on Simple-Talk. You can read it in below URL.
http://www.simple-talk.com/2006/01/19/aspnet-configuration/
Commets are highly appreciated.
Posted by Ludmal De Silva | with no comments
I've been asked this question several times from my collegues and some of my friends. How to export the Default Provider model table/sp structure to custom database. Since ASP.NET 2.0 uses its own SQL schema to do CRUD operations, as developers we might think how do we get the default SQL schema to our own database. So that we can intregrate our exisiting tables/sp with the ASP.NET 2.0 default database.
       To make the job easier microsoft has given a visual tool aspnet_regsql.exe. You can find this tool in C:\WINNT\Microsoft.NET\Framework\v2.0.50215. Run the tool by double clicking and you will get a Welcome window with some brief help. Click next to continue and select Configure Sql Services for Applications then click next, select the database you want to export the tables/sp's and then click next. Your done! You have successfully generated the default sqlschema to your custom database. Goto the database and now you can view tables structure and the sproc's which generates from the tool. By changing the Connection String in the web config file you can use your database with the ASP.NET Provider Model.(Profile/Personalization). The best thing is, you dont have to stick to the default database which creates when you use the provider model. 
Posted by Ludmal De Silva | with no comments

I have done some ASP.NET 2.0 apps but still bothers me is, its design view. I mean the way we have to design the layout. I know there are some new features like layouts, Templates and so forth. The small arrows are really annoying when we move the mouse over the tables or layouts. To select a table or a layout is annoying task compare to earlier version. And sometimes the table cells are not aligning the way we wanted. Since I’m not a designer it should be easier for developers to do some simple design. I wasted my time on designing rather than coding. I hate the small arrows which pop ups when we move the mouse. I need to find a way to ignore them. I still like the VS 2003 design. Of course there more enormous features in 2.0 but sometimes I feel………

Posted by Ludmal De Silva | with no comments
For those who couldn't understand the Provider Model in my presentation this will be great place to start learn. I will do a presentation about Provider Model once i get a chance.  http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/ASPNETProvMod_Intro.asp.
Posted by Ludmal De Silva | with no comments

Due to tight schedule I had last week couldn’t post any technical stuff in my blog. As im more a technical blogger I thought of posting some new stuff in asp.net 2.0. So let’s talk about PreviousPage property in Page object. It’s new to the ASP.NET 2.0.  When we do Server.Transfer we can get a reference to the previous page using PreviousPage property. Let’s imagine that you need to get the value of the textbox in the previous page. All you have to do is simply use the PreviousPage property in the current page instance and call the FindControl method.(Remember you must use Sever.Transfer). Check the code sample below.

  if (Page.PreviousPage != null) {
            this.Label1.Text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
        }
Hope you got the clear idea of the PreviousPage property. If not leave a comment..
Posted by Ludmal De Silva | with no comments
Last Wednesday I did my first presentation on ASP.NET 2.0 Configuration Tools. Because of the time limit I couldn’t explained it properly. But I hope those who attend to my presentation learned something. Since it was my first presentation  there are lot to learn about doing presentations. But I guess it went well. Thanks for the comment and emails. Cheers!![:)]