First fill the datatable or dataset as normal
then if we want to filter the datatable / dataset depending upon say textboxchanged event
string expr = "";
expr = "_ItemName like '"+txt.Text+"*'";
dt.DefaultView.RowFilter = expr;
dgv.DataSource = dt.DefaultView;
Here _ItemName is the Column used for Filtering
Wednesday, October 27, 2010
Monday, March 1, 2010
Summary for file encryption and decryption
Import IO and Security.Cryptography
File Decryption
Dim ue As New UnicodeEncoding()
Dim key As Byte() = ue.GetBytes(pword)
Dim rm As New RijndaelManaged()
Dim fs1 As New FileStream(file_path, FileMode.Open)
path = save_path
Dim str As String(), st As String()
str = file_path.Split("\"c)
Dim str1 As String = str(str.Length - 1)
st = str1.Split("."c)
save_path = path & "\" & st(0) + "." & st(1)
Dim i As Integer = 0
Dim fs2 As New FileStream(save_path, FileMode.Create)
Dim cs As New CryptoStream(fs2, rm.CreateDecryptor(key, key), CryptoStreamMode.Write)
While (True)
Dim d As Integer
d = fs1.ReadByte()
If d = -1 Then
Exit While
End If
cs.WriteByte(Convert.ToByte(d))
End While
cs.Close()
fs1.Close()
File Encryption
Dim ue As New UnicodeEncoding()
Dim key As Byte() = ue.GetBytes(pword)
Dim rm As New RijndaelManaged()
Dim fs1 As New FileStream(file_path, FileMode.Open)
path = save_path
Dim str As String(), st As String()
str = file_path.Split("\"c)
Dim str1 As String = str(str.Length - 1)
save_path = path + "\" + str1 + ".cpt"
Dim i As Integer = 0
While (True)
If File.Exists(save_path) Then
st = str1.Split("."c)
i = i + 1
save_path = path + "\" & st(0) & "(" & i & ")" & "." & st(1) & ".cpt"
Else
Exit While
End If
End While
Dim fs2 As New FileStream(save_path, FileMode.Create)
Dim cs As New CryptoStream(fs2, rm.CreateEncryptor(key, key), CryptoStreamMode.Write)
While (True)
Dim d As Integer
d = fs1.ReadByte()
If d = -1 Then
Exit While
End If
cs.WriteByte(Convert.ToByte(d))
End While
cs.Close()
fs1.Close()
Write values in registry
First import Microsoft.win32
'select a prticular registry directory
registrydirectory = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
'createt ou own registry directory
registrydirectory.CreateSubKey("MyDir")
'open our own registry directory
registrydirectory = Registry.LocalMachine.OpenSubKey("Software\MyDir", True)
'write values and version
registrydirectory.SetValue("String Type", "String Data")
registrydirectory.Close()
Connection String Using Access 2007
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "Location with filename as String" + ";Jet OLEDB:Database Password=;"
Script for adjust the web pages as center
function align()
{
var lmt = document.getElementById('center');
var container = document.documentElement;
if(lmt && container)
{
var containerHeight;
if (container.innerWidth)
{
containerHeight = container.innerHeight;
}
else
{
containerHeight = container.clientHeight;
}
var lmtHeight;
if (lmt.innerWidth)
{
lmtHeight = lmt.innerHeight;
}
else
{
lmtHeight = lmt.offsetHeight;
}
var y = Math.ceil((containerHeight - lmtHeight) / 2);
if(y <>
{
y = 0;
}
lmt.style.position = "relative";
lmt.style.top = y + "px";
}
if (document.getElementById)
{
document.body.style.visibility = 'visible';
}
}
function addevent(obj,evt,fn,capt){
if(obj.addEventListener)
{
obj.addEventListener(evt, fn, capt);
return true;
}
else if(obj.attachEvent)
{
obj.attachEvent('on'+evt, fn);
return true;
}
else return false;
}
if (document.getElementById && document.getElementsByTagName)
{
addevent(window, 'load', align, false);
addevent(window, 'resize', align, false);
}
Tuesday, November 3, 2009
Disable Close button in Windows form
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;
}
}
Friday, October 23, 2009
Getting all machines in LAN using VB.NET
Drag one list box and name it as LBox
In form load write the below code
Dim childEntry As DirectoryEntry
Dim ParentEntry As New DirectoryEntry
Try
ParentEntry.Path = "WinNT:"
For Each childEntry In ParentEntry.Children
Select Case childEntry.SchemaClassName
Case "Domain"
Dim SubChildEntry As DirectoryEntry
Dim SubParentEntry As New DirectoryEntry
SubParentEntry.Path = "WinNT://" & childEntry.Name
For Each SubChildEntry In SubParentEntry.Children
Select Case SubChildEntry.SchemaClassName
Case "Computer"
LBox.Items.Add(SubChildEntry.Name)
End Select
Next
End Select
Next
Catch Excep As Exception
MsgBox("Error While Reading Directories")
Finally
ParentEntry = Nothing
End Try
On listbox changed write the below code to get the ip address
Try
Dim IPHEntry As Net.IPHostEntry
Dim IPAdd() As Net.IPAddress
Dim localHost As String
localHost = Dns.GetHostName()
IPHEntry = Dns.GetHostByName(LBox.SelectedItem.ToString())
IPAdd = IPHEntry.AddressList
Dim i As Integer
For i = 0 To IPAdd.GetUpperBound(0)
'Console.Write("IP Address {0}: {1} ", i, IPAdd(i).ToString)
MessageBox.Show(IPAdd(i).ToString)
'txtIp.Text = IPAdd(i).ToString
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
In form load write the below code
Dim childEntry As DirectoryEntry
Dim ParentEntry As New DirectoryEntry
Try
ParentEntry.Path = "WinNT:"
For Each childEntry In ParentEntry.Children
Select Case childEntry.SchemaClassName
Case "Domain"
Dim SubChildEntry As DirectoryEntry
Dim SubParentEntry As New DirectoryEntry
SubParentEntry.Path = "WinNT://" & childEntry.Name
For Each SubChildEntry In SubParentEntry.Children
Select Case SubChildEntry.SchemaClassName
Case "Computer"
LBox.Items.Add(SubChildEntry.Name)
End Select
Next
End Select
Next
Catch Excep As Exception
MsgBox("Error While Reading Directories")
Finally
ParentEntry = Nothing
End Try
On listbox changed write the below code to get the ip address
Try
Dim IPHEntry As Net.IPHostEntry
Dim IPAdd() As Net.IPAddress
Dim localHost As String
localHost = Dns.GetHostName()
IPHEntry = Dns.GetHostByName(LBox.SelectedItem.ToString())
IPAdd = IPHEntry.AddressList
Dim i As Integer
For i = 0 To IPAdd.GetUpperBound(0)
'Console.Write("IP Address {0}: {1} ", i, IPAdd(i).ToString)
MessageBox.Show(IPAdd(i).ToString)
'txtIp.Text = IPAdd(i).ToString
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Subscribe to:
Posts (Atom)