Search Results:

Thursday, June 16, 2016

Filter datatable using LINQ in VB.NET

Below is a simple LINQ that you can use to filter the DataTable.


AsEnumerable() method to return the input type DataTable as IEnumerable.

CopyToDataTable() method takes the results of the filtered query and copies into a new DataTable that you can use to work with the filtered data.

-------------------------------------------------------------------------
         Dim filteredTable As DataTable = (From n In dt.AsEnumerable()
                                           Where n.Field(Of Int32)("id") = 1
                                           Select n).CopyToDataTable()
-------------------------------------------------------------------------

Feel free to leave your comments or suggestions. Thank you.

Wednesday, October 30, 2013

Adding Handlers for Controls {Code}

Public Class Userdetails
Dim cnn As SqlConnection = New SqlConnection(My.Settings.ConnectionString)
Dim strSQL As String
Private pUserId As Integer
Private pNewUser As Boolean = False
Private IsDirty As Boolean = False
Private Sub AddSaveHandlers(ByVal c As Control)
For Each ctrl As Control In c.Controls
If ctrl.Controls.Count > 0 Then
AddSaveHandlers(ctrl)
End If
Select Case ctrl.GetType.Name.ToUpper
Case "TEXTBOX", "COMBOBOX"
AddHandler ctrl.TextChanged, AddressOf SetPromptSaveTrue
Case "CHECKBOX"
AddHandler CType(ctrl, CheckBox).CheckStateChanged, AddressOf SetPromptSaveTrue
End Select
Next
End Sub
Private Sub SetPromptSaveTrue(ByVal sender As System.Object, ByVal e As System.EventArgs)
IsDirty = True
End Sub
Private Sub Userdetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddSaveHandlers(Me)
End Sub
Private Sub Userdetails_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Dim savedata As DialogResult
If IsDirty Then
savedata = MessageBox.Show("Do you want to save your changes?", "Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
Select Case savedata
Case Windows.Forms.DialogResult.Yes
Call btnSave_Click(sender, e)
Case Windows.Forms.DialogResult.Cancel
e.Cancel = True
Case Else
IsDirty = False
End Select
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class

VSS Writers and associated Services

Handreference linking VSS Writers to Services


VSS Writer Service Name Service Display Name

ASR Writer
VSS Volume Shadow Copy
BITS Writer BITS Background Intelligent
Transfer Service

COM+ REGDB Writer
VSS Volume Shadow Copy
IIS Config Writer AppHostSvc Application Host Helper
Service

IIS Metabase Writer
IISADMIN IIS Admin Service
Microsoft Exchange Writer MSExchangeIS Microsoft Exchange
Information Store
Microsoft Hyper-V VSS Writer vmms Hyper-V Virtual Machine
Management
Registry Writer VSS Volume Shadow Copy

Shadow Copy Optimization Writer
VSS Volume Shadow Copy

System Writer
CryptSvc Cryptographic Services

WMI Writer
Winmgmt Windows Management
Instrumentation

Thursday, October 17, 2013

Convert a Base64 String into a PDF File

Recently I had the need to decode a Base64 string and make a PDF of it.  Usually I would've written a small utility app, but this time I rolled with powershell: 

function decodeBase64IntoPdf([string]$base64EncodedString)
{
    $bytes = [System.Convert]::FromBase64String($base64EncodedString)
    [IO.File]::WriteAllBytes("C:\Users\medmondson\Desktop\file.pdf", $bytes)
}

I'm impressed with how quickly I can knock out a script like this (yes they are .NET assemblies) without having to load a new VS solution. Of course a lot more could be done to this (file format via an argument for example) but I thought I'd share it raw as I know I'll need to use it again one day.

From Matt's Blog


Thursday, May 27, 2010

Tuesday, May 25, 2010

Why Invisible Column?

One might ask that why should I use an invisible column in the first place. There are many reasons of making the column invisible. You might want to use a column as the primary key which retrieves the value from the database and display it using the GridView control. Since, primary key is a confidential data you want might to hide it from the users. Another reason of making the column invisible is that you might want to have some additional information to save an extra trip to the database. Please note that the second scenario should not be used to display many columns as this will increase the View State and thus the size of the page large.

Using the DataKeys Property:

The simplest way to access the primary key is by using DataKeys property of the GridView control. DataKeys property represents the column which is to be used as the primary key. In this article I will use my custom database "Tasks" and display the columns "Title", "Description", "DateCreated" in the GridView control. Apart from the columns from the database the GridView also contains a CheckBox Template Column which is used to check the tasks which are completed. Take a look at the HTML below to have a clear idea.

<asp:GridView ID="gvInComplete" runat="server" AutoGenerateColumns="False" CellPadding="4"

ForeColor="#333333" GridLines="None" DataKeyNames="TaskID">

<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />

<Columns>

<asp:BoundField DataField="Title" HeaderText="Title" />

<asp:BoundField DataField="Description" HeaderText="Description" />

<asp:BoundField DataField="DateCreated" HeaderText = "Date Created" />

<asp:TemplateField HeaderText="Select">

<ItemTemplate>

<asp:CheckBox ID="chkSelect" runat="server" />

ItemTemplate>

asp:TemplateField>

Columns>

asp:GridView>

As, you can see in the code above the DataKeyNames property is set to "TaskID" which, is the primary key in the table. Now, let's see how we can access all the TaskID of the rows which are checked using the CheckBoxes.

DataKey key;

foreach (GridViewRow row in gvInComplete.Rows)

{

bool result = ((CheckBox)row.FindControl("chkSelect")).Checked;

if (result)

{

key = gvInComplete.DataKeys[row.RowIndex];

Response.Write((int)key.Value);

}

}

In the code above I am iterating through all the rows in the GridView control. If I find a row that is checked then I gets the primary key of the row using the GridView DataKeys collection. The Row class property RowIndex will contain the index of the current row.

This is pretty simple right! But what if I want to access another column which is not a primary key. This can be done by using a Template Column inside the GridView control.

Accessing Invisible Column Using Template Field:

To access the invisible column using Template Field is very straight forward. All you need to do is to make the Template Field invisible and use the control inside the Template Field to access the values. Check out the following HTML code:

<asp:TemplateField Visible="False">

<ItemTemplate>

<asp:Label ID="lblTaskID" runat="server" Text='<%# Eval("TaskID") %>' />

ItemTemplate>

asp:TemplateField>

In the above HTML code I have simply defined a Label control inside the ItemTemplate property of the Template Field. The Template Field is made invisible so, the user will not see it on when it is bound to the GridView control. You can access the TaskID using the following code:

int taskID = 0;

Task task = new Task();

foreach (GridViewRow row in gvInComplete.Rows)

{

bool result = ((CheckBox) row.FindControl("chkSelect")).Checked;

if (result)

{

taskID = Convert.ToInt32(((Label)row.FindControl("lblTaskID")).Text);

task.UpdateTask(taskID);

}

}

In the above code I am simply iterating through the GridView rows and when I find that the checkbox is checked then I get the value from the Label control which in this case is TaskID. After, I get the TaskID I can perform any function on it in my case UpdateTask.

I hope you liked the article, happy coding!

Copied From:http://www.highoncoding.com/Articles/178_Access%20GridView%20Invisible%20Columns.aspx

This is just for educational purpose only....


Tuesday, May 18, 2010

Sending Email From Web Page using asp.net

Hope this link will help you find the solution you are looking

http://www.4guysfromrolla.com/articles/072606-1.aspx