C# running Access Query with parameters ADO

by ebarcza 3/13/2012 11:40:00 AM
 public DataTable GetFirmwareByBoardID(int boardID)
            GalleryDatabase db = DataBaseFactory.getDataBase(DataBaseName);
            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = new OleDbConnection(db.GetConnection().ConnectionString);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "qryGetFirmwareByBoardID";
            cmd.Parameters.AddWithValue("@prodCode", boardID);
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataTable dt = new DataTable();
            return dt;


.NET | Access

Merging Data Tables in C#

by pencilvac 3/9/2012 12:16:00 PM

Merging data tables in C# is incredibly easy. If you have two tables of data pulled from the database:

In this situation our two tables have the same columns.

using System.Data; //include in your code behind so you can use data tables.


DataTable dt = Contract.GetDealContracts(pCompanyID, -1,42);

DataTable dt2 = Contract.GetDealContracts(pCompanyID, -1, 40);



You can then merge the two tables into one by simply:

dt.Merge(dt2); // table1.Merge(table2);


BOOM- two tables, now one table, with all your data. 

Tags: , , ,

.NET | ASP.NET Enterprise Library

C# format string as a number with ToString()

by ebarcza 2/17/2012 7:00:00 AM
int x = 25600;
//No Decimals
string numString = x.ToString("N0");

//With Decimals
string numStringDec = x.ToString("N5");



Overriding AspNetSqlMembershipProvider in ASP.NET 4.0

by rbellantoni 11/8/2011 7:45:00 AM

If you are having as much trouble as I did figuring out where the hell all the web.config settings went after creating Users and Roles using the built in administration tools in .NET then read on!

It turns out, that in ASP.NET 4.0, they removed some of the "clutter" from the web.config since some web.configs were getting very large with configurations and developer added keys etc. So they moved it to a machine.Config file inside of the framework folder. What this means is that they took out all the standard settings in the web.config that are required to run a website so you don't have to see them anymore....HOWEVER, they ALSO moved the default membership provider settings as well. So what does this mean?  It means you can't just make a tweak to the default settings, you need to actually implement your OWN web.config provider as follows:

                <!--<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" 
                 enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0"
 passwordAttemptWindow="10" applicationName="/"/>-->
                <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" 
connectionStringName="test" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="500" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
                <add name="DisplayName"/>
        <roleManager enabled="true">
                <add connectionStringName="test" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
                <!--<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>-->
                <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider"/>

Now you can go ahead and change the settings as necessary.


.NET | ASP.NET Enterprise Library | SQL SERVER

Visual Studio Empty Website Data Source window

by ebarcza 8/3/2011 8:28:00 AM
From time to time when I go to modify an RDLC, i get an empty Data Source window... here's the crazy ass workaround to get it back.
  • 1)Add an aspx page
  • 2)Add ReportViewer control to the new page in design mode
  • 3)Go to design mode--> click the arrow in the upper right corner and choose Design new report.
  • 4.)Now Close it
  • 5.)Go back to your original RDLC and the Website data source window is populated again.

      Works on my machine....



ASP.NET menu sub-items dropdown behind image

by ebarcza 8/1/2011 7:24:00 AM

Sometimes when you have menu sub-items in a .NET menu control they will be hidden behind an image if they happen to overlap. To fix this, set the z index of the dynamicMenu css class


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="menu.ascx.cs" Inherits="YANKEE_WEB.menu" %>
<asp:Menu ID="mnuYANKEE" runat="server" DataSourceID="SiteMapDataSource1" 
            Orientation="Horizontal" ForeColor="#8D4F59" Font-Names="Arial" 
                Font-Size="Medium" Font-Bold="True" 
                CssClass="menumain" onprerender="mnuYANKEE_PreRender" DynamicHoverStyle-BackColor="#CCCCFF">
            <StaticMenuStyle HorizontalPadding="4px" />
            <StaticSelectedStyle ForeColor="#8D4F59" />
            <StaticMenuItemStyle HorizontalPadding="15px" />
            <DynamicHoverStyle BackColor="#cdcdcd" ForeColor="#500000" Font-Overline="False"
                                Font-Underline="false" Font-Bold="true"/>
            <DynamicMenuStyle BackColor="#FFFFFF" BorderColor="" CssClass="dynamicMenu" VerticalPadding="0px" HorizontalPadding="0px" />
            <DynamicMenuItemStyle Width="200px" CssClass="dynamicMenuItem" Font-Size="5pt" ForeColor="#8D4F59" />
            <StaticHoverStyle ForeColor="#500000" />
                <asp:MenuItem Text="Home" Value="Home"></asp:MenuItem>

Now the css class for the DynamicMenuStyle

.dynamicMenu {



C# Check for Null Querystring

by ebarcza 7/7/2011 3:54:00 AM
 if (Request.QueryString["ContractID"] != null && Request.QueryString["ContractID"].ToString() !="")
                int contractID = int.Parse(Request.QueryString["ContractID"].ToString());
                Contract contract = new Contract(contractID);
                hdnContractID.Value = contractID.ToString();

Tags: , ,


Cache Using ObjectDataSource

by rbellantoni 8/26/2010 7:02:00 AM

I needed to bind a large dataset to a gridview, it also contained numerous calculations that slowed down the database call, so I wanted to implement caching for the gridview I was using. 

So I used the default Caching on the ObjectDataSource. Which works great and well except for when you want to programatically refresh the data (say a new filter to be added). Turns out you can actually do it.


First make sure that in Page Load you set the CacheKeyDependency if it isn't set (you can also manually set it on the aspx page as a property of the ObjectDataSource):

        if (!IsPostBack)
            //Create CacheKeyDependency if it doesn'tnot exists
            if (Cache[ObjectDataSource1.CacheKeyDependency] == null)
                Cache[ObjectDataSource1.CacheKeyDependency] = new object();

In your code whenever you want the Select() of your ObjectDataSource to fire or just rebind from the database make this call:

Cache[ObjectDataSource1.CacheKeyDependency] = new object(); 

This allows you to programatically renew/refresh your datasource at will while still retaining the Cache abilities for paging/sorting/grouping etc.



Get the Selected Radiobutton from Radio Button List in Javascript

by ebarcza 8/20/2010 11:56:00 AM

Just pass in the clientid of the Radio button list control and this function will return the ID of the selected radio button so you can do what you want with it.

function GetRBLSelectionID(RadioButtonListID) {
    var RB1 = document.getElementById(RadioButtonListID);
    var radio = RB1.getElementsByTagName("input");
    var isChecked = false;
    var retVal = "";
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            retVal = radio[i].id;
    return retVal;



Tags: , ,

.NET | JavaScript

Export ListView to Excel

by jrose 8/20/2010 10:02:00 AM

All results that I came across when performing a search for export listview to excel were related to instances of Windows.Forms.ListView and not System.Web.UI.WebControls.ListView.


Attached are the two functions necessary to export instances of System.Web.UI.WebControls.ListView to Excel.

public override void VerifyRenderingInServerForm(Control control) { }

protected void btnExport_Click(object sender, EventArgs e)
    Response.Buffer = true;
    Response.ContentType = "application/vnd.ms-excel";
    Response.Charset = "";
    this.EnableViewState = false;
    StringWriter stringWriter = new StringWriter();
    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

Tags: , , ,

.NET | ASP.NET AJAX | Excel Programming

Powered by BlogEngine.NET
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail


<<  October 2018  >>

View posts in large calendar

Recent comments



The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2018

Sign in