Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Bonnie Berent's Tips
Bonnie DeWitt, April 1, 2006
Great tips for .NET developers
Summary
Great tips for .NET developers
Description

Hiding Properties on the Property Sheet
Sometimes on a control class you're designing, you may want to prevent some properties from showing up on the Property Sheet. For instance, your control may have no use for the .Text property, so why bother having it show up on the Property Sheet.

The solution is to use the Browseable attribute in the property's definition.
[Browsable(false)]
public override string Text
{
   get
   {
      return base.Text;
   }
   set
   {
      base.Text = value;
   }
}

from a solution provided by Dave Foderick in Message #1050680

How To Include the Schema with the Data's XML
As most people know, if you want to serialize a DataSet's data to XML, all you have to use is the DataSet's .GetXml() method, which returns a string of XML representing the data.

But what do you do if you want to include the DataSet's schema along with the data? It's a few more lines of code, but not too bad really:
MemoryStream ms = new MemoryStream();
MyDataSet.WriteXml(ms, XmlWriteMode.WriteSchema);

ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms);
string xml = sr.ReadToEnd();

from a solution provided by Bonnie Berent in Message #1086856

Why WebForms And WinForms Access SQL Server Differently
This question comes up a lot on the Forums:

"I have a SQL Server database residing on my PC. I can successfully query tables in this database from a .Net WinForm. However, if I attempt to perform the same queries using a .Net WebForm, I get a login failed error message. What's up with that?"

It has to do with permissions. Your WinForm runs as YOU, or I should say as the user account that you logged into windows as (which, if you are like most people, that is either Administrator or equivalent). By default SQL Server(MSDE) sets up a login BUILTIN\Administrators that is in the System Administrator server role.

So, indirectly your windows user has sa rights to SQL (when you use windows authentication), so does your WinForms app.

WebForms are run by the asp.net worker process. This process is set up to run as the ASPNET user or (NT Authority\Network Server on 2003). This user is not by default in the local machine admin group, which means it doesn't have sa rights to SQL Server.

So, you have to go into your SQL Server, create a login that grants localmachinedomain\ASPNET user rights to either the db in question, or on your test machine you can put this sql user into the System Administrator domain.

Another approach would be to put the ASPNET user into the local machine Administrator group.

Finally instead of using trusted connection in your connection string you could use a SQL Server account/password. A lot of devs use sa while developing.

from a solution provided by Bob Archer in Message #949387

Adding New Rows to a WinForm DataGrid
How do you disable this functionality? It's a trick question, because the answer isn't in the DataGrid itself, it's in the DataSource for the DataGrid. If your grid's DataSource is a Table, use the DefaultView.
MyTable.DefaultView.AllowNew = false;

from a solution provided by Kevin Goff in Message #1045174

Bonnie DeWitt, Geneva Systems Group
Bonnie is currently one of the principals of Geneva Systems Group. Call her the Senior Software Engineer, or even call her the VP of Engineering. She has no official title at the moment. Bonnie has been writing software in various languages for about 30 years. Bonnie's current focus on C# .NET applications began in early 2002. She has been a Microsoft C# MVP since Oct 2003 and an active member of the .NET online community.
More articles from this author
Bonnie DeWitt, September 1, 2005
Great tips for .NET developers
Bonnie DeWitt, October 1, 2005
Great tips for .NET developers
Bonnie DeWitt, November 1, 2005
Great tips for .NET developers
Bonnie DeWitt, December 1, 2005
Great tips for .NET developers
Bonnie DeWitt, April 1, 2009
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, February 1, 2006
Great tips for .NET developers
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers
Bonnie DeWitt, May 1, 2006
Great tips for .NET developers
Bonnie DeWitt, June 1, 2006
Great tips for .NET developers
Bonnie DeWitt, July 1, 2006
Great tips for .NET developers
Bonnie DeWitt, August 1, 2006
Great tips for .NET developers
Bonnie DeWitt, September 1, 2006
Great tips for .NET developers
Bonnie DeWitt, October 1, 2006
Great tips for .NET developers
Bonnie DeWitt, November 1, 2006
Great tips for .NET developers
Bonnie DeWitt, December 1, 2006
Great tips for .NET developers
Bonnie DeWitt, January 1, 2007
Great tips for .NET developers
Bonnie DeWitt, February 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers.
Bonnie DeWitt, April 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2007
Good tips for .NET developers.
Bonnie DeWitt, May 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, June 1, 2007
Great tips and tricks for .NET developers.
Bonnie DeWitt, July 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, August 1, 2007
Great tips for .NET developers
Bonnie DeWitt, September 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, February 1, 2008
Great tips from the Universal Thread .NET community.
Bonnie DeWitt, March 1, 2008
Great tips for .NET developers selected from the community by Bonnie Berent.
Bonnie DeWitt, April 1, 2008
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, January 1, 2006
Great tips for .NET developers