CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

John Papa [MVP C#]

.NET Code Samples, Data Access, and Other Musings

September 2005 - Posts

  • What's Your Favorite New VS.NET 2005 Feature of the Week?

    This week I have been spending some free time in the reviewing the VS.NET 2005 Release Candidate. There are some nice features in the product that I am really excited about such as the new data designers and the TableAdapter in ADO.NET 2. Of course the oft discussed generics are pretty awesome, too. Partial classes, an oldie but goodie (hard to believe that feature seems like it has been around so long and its not in a live version yet). I'll be posting what I find in the VS.NET 2005 RC in the very near future.

    Thereis a lot to talk about! "Edit and continue", generics, code snippets, etc.  So what is your favorite new feature? [ at least for this week :-) ]

    Posted Sep 30 2005, 09:50 AM by John Papa with 1 comment(s)
    Filed under:
  • SQL Server 2005 Tools Where Are You?

    So far the VS.NET 2005 Releaes Candidate has ben a smooth ride. The install went very smooth, the app loaded with no hiccups and many of my beta 2 projects ran just fine. Of course, its still early, but I am happy so far.

    <growl>So now I want to jump into the September CTP of SQL Server 2005 via the management tools instad of just hitting the SQLExpress DB. This is where I have just about thrown the darn thing out the window! I have tried to install it 3 times now (uninstalling after each failure). It installs the DB engine, notification services, reporting services and integration services just fine ... but when it gets to the Tools it pukes. I can use the database I just can't use the nice and friendly tools to get to the database easily. I won't bore you with everything I tried but needless to say that it shouldn't be like this. Even the logs that it referred me to were emtpy.</growl>

    Anyway, I wills till be using the SQL 2005 Sep CTP's DB engine which I must say I have been very impressed with in my brief encounters with it this past week (and in previous CTP's). Hopefully I'll figure out how to get the Tools installed. I hope you all don't run into this issue.

    Posted Sep 27 2005, 01:18 AM by John Papa with 5 comment(s)
    Filed under:
  • Talkin 'Bout ADO.NET 2 and ASP.NET GridView, DetailsView and ObjectDataSource

    As I mentioned in a post a few weeks back, I will be presenting a few topics at VSLive Orlando. This past week I was sprucing up my code samples with the latest VS.NET 2005 release candidate and I was impressed with the little things in it. Some of the minor bugs were really paid attention to and the speed enhancements that were there in beta 2 are still there (yes, I was a bit worried that some of the DataSet improvements might be X'd out due to time or some funky reason). Anyway, I am really excited about presenting in Orlando because of the close timing to the release of VS.NET 2005. If you have been to any of my presentations in the past you'll know that I tend to use my slides as a talking point but that I prefer to show code examples to show how things work. I'm a visual guy :-) Anyway, I hope to see some of you there!

    Oh ... and I am almost confirmed for a trip out west to Las Vegas for a Academic conference. I don't have all the information yet but it appears to be a conference for the IT and IS professors of colleges and universities. I think it will be awesome to talk with the professors and see what they are teaching the next generation of code junkies like me. I am really looking forward to it.

     

    Posted Sep 23 2005, 10:29 PM by John Papa with no comments
    Filed under: ,
  • VS.NET 2005 Release Candidate Installation

    I went out to grab the VS.NET 2005 Release Candidate and the SQL Server 2005 September CTP a few days ago from the MSDN subscriber site. The download took a loooooooong time since the 2 combined where over 4 GB. But all in all the site was responding well and I can't really complain since the download speeds were pretty good. Virtual PC makes the installation process so much easier. (I recommend reading Mark's article on VPC for some pointers.)

    Overall, the installation took about 1.5 hours for VS.NET 2005 RC and another 15 minutes for the MSDN documentation on my VPC image. I'll be diving into it this weekend so I can update some of my test code that I have written and see what changes or refactors I might need to make. I'm interested in seeing how System.Transactions has been flushed out and in testing the rest of the ADO.NET modifications that have been discussed by the DataWorks team. I'll blog more on these topics and the changes as I get deeper.

    Posted Sep 22 2005, 03:36 PM by John Papa with 2 comment(s)
    Filed under:
  • Sending Email from a Web Page with ASP.NET 2.0 beta

    Here is another quick example of how to send an email from a web page, this time using ASP.NET 2. (for ASP.NET 1.1, click here) The code for the ASP.NET 1.1 technique needs to be refactored to be used in ASP.NET 2.0 since the System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail classes become obsolete in .NET 2. Instead, there are now the System.Net.Mail.MailMessage and System.Net.Mail.SmtpClient classes, as shown below:

     

        1         protected void btnSend_Click(object sender, EventArgs e)

        2         {

        3             //Assuming the required fields have been validated using a validator ...

        4 

        5             MailMessage msg = new MailMessage();

        6             msg.From = new MailAddress(txtFrom.Text);    //you can also add a From Name for display purposes

        7             msg.To.Add(txtTo.Text);                      //you can also add a To Name for display purposes

        8             if (txtCc.Text.Length > 0)

        9                 msg.CC.Add(txtCc.Text);                  //you can also add a CC Name for display purposes

       10             if (txtBcc.Text.Length > 0)

       11                 msg.Bcc.Add(txtBcc.Text);                //you can also add a Bcc Name for display purposes

       12             msg.Subject = txtSubject.Text;

       13             msg.Body = txtBody.Text;

       14 

       15             SmtpClient smtp = new SmtpClient(txtSMTPServer.Text);

       16             smtp.Send(msg);

       17         }

     

     

    Posted Sep 19 2005, 05:18 PM by John Papa with 7 comment(s)
    Filed under:
  • Sending Email from a Web Page with ASP.NET 1.1

    Here is a quick code example of how to send an email message from a web page using ASP.NET. First, I drew up a quick and dirty web page UI.

     

    I added some required field validator controls for the To, From and Message fields. I also added some regular expression validator controls for all of the email address fields. It really is nice that the regular expression validator control comes with predefined expressions that you can choose form a drop down list in the property window. It offerred this expression for the email address, for example:

    ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"

    For those of you familiar with CDO or the good ol' CDONTS code that was popular for sending emails with traditional VB and ASP, there is a different namespace and class structure for this purpose in ASP.NET called System.Web.Mail.It is very easy to use. This code executes when the user clicks the send button. It creates an instance of the MailMessage class and sets the basic properties. Then it sets the priority and format using the provided enumerators. You can also send attachments, too, if needed.

        1         private void btnSend_Click(object sender, System.EventArgs e)

        2         {

        3             MailMessage msg = new MailMessage();

        4             msg.From = txtFrom.Text;

        5             msg.To = txtTo.Text;

        6             msg.Cc = txtCc.Text;

        7             msg.Bcc = txtBcc.Text;

        8             msg.Subject = txtSubject.Text;

        9             msg.Body = txtBody.Text;

       10             msg.Priority = MailPriority.Normal;

       11             msg.BodyFormat = MailFormat.Text;

       12             SmtpMail.SmtpServer = "";

       13             SmtpMail.Send(msg);

       14         }

    Here I set the SmtpServer property to an empty string. This tells the MailMessage object to use the default mail server. SmtpServer is a static property so if you change it, every ASP.NET page that sends a message will be effected. To avoid any possible confusion, I always like to set this property explictly so I don't have to worry about some ther page causing me a debugging heartache. You might also notice that the MailMessage class does not have a Send method. Instead, you  create an instance of the SmtpMail class and execute its Send method. The Send method can accept either a MailMessage object or the series properties that make up a message (a string for from, to, subjetc, etc.)

    That's it really. There are other features and lots of creative thing that you can do with this. But for those looking just to send a simple email message this is a nice quick example.

    Update: If you are looking for a quick ASP.NET 2.0 example, click here to go to http://codebetter.com/blogs/john.papa/archive/2005/09/19/132252.aspx.

    Posted Sep 19 2005, 03:59 PM by John Papa with 8 comment(s)
    Filed under:
  • Enterprise Library's Data Access Application Block - Part 3

    In the October 2005 issue of MSDN Magazine I continued my discussion of the Enterprise Library’s Data Access Application Block. This is the final episode in the trilogy where I explore the Enterprise Library DAAB in my Data Points column. I had a lot of good feedback from parts 1 and 2. OK, so I generally don't like write 3 part articles, but I just kept running out of room (after all, magazines have space limitations). There is just so much to say about the Ent Lib DAAB :-)

    You can read the article online here. Or you can read the whole series of the Ent Lib DAAB discussion at these links:

     

    In the upcoming issues I'll be getting into ADO.NET 2 and some of its features. I've also been toying with a follow up article on system.transactions since so much has changed and I have had so many good comments and questions on the topic.

  • Quick DataGridView Quiz

    A buddy of mine recently struggled with one of those "I can't beleive I didn't see it" issues. It went something like this ...

    Assuming:

    • you have a C# Windows Form application
    • a WinForm
    • a DataGridView
    • a button called button1
    • a valid connection string
    • a valid sql statement

    What's wrong with this code, if anything?:

        1         private void button1_Click(object sender, EventArgs e)

        2         {

        3             SqlConnection cn = new SqlConnection(@"server=VSTSB2;database=northwind;integrated security=true;");

        4             SqlCommand cmd = new SqlCommand("select * from customers", cn);

        5             SqlDataAdapter adpt = new SqlDataAdapter(cmd);

        6             DataSet ds = new DataSet();

        7             adpt.Fill(ds);

        8             dataGridView1.DataSource = ds.Tables[0];

        9         }

     

More Posts