Show a list View in Group

Monday, December 29, 2008

This will show the list view Group

Dim ObjListItem As ListViewItem
Dim ObjListViewGroup As ListViewGroup
ObjListViewGroup = New ListViewGroup("File Name :" & FileName)
LvwBills.Groups.Add(ObjListViewGroup)
For iCount = 0 To 10                
                ObjListItem = New ListViewItem(ObjListViewGroup)
                ObjListItem.SubItems.Add("ABCD"              
                LvwBills.Items.Add(ObjListItem)
                PFileProcessBar.Value = iCount
Next

File opertation in VB.Net

Friday, December 26, 2008

imports system.io
Public Class Form1
    Public Sub MaintainintoFile(Optional ByVal StringtoWrite As String = "Error Not Trapped")
        Try
            Dim StartLog As Boolean
            Dim FName As String

            Dim LogDirName As String
            Dim BaseErr As String = ""
            Dim fs As FileStream
            Dim fileWrite As StreamWriter
            Dim dir As String
            StartLog = True
            dir = Application.StartupPath
            LogDirName = dir & "\Log\"
            If Not Directory.Exists(LogDirName) Then Directory.CreateDirectory(LogDirName)

            FName = LogDirName & "Log.log"
            If File.Exists(FName) Then
                fs = New FileStream(FName, FileMode.Append, FileAccess.Write, FileShare.Read)
                fileWrite = New StreamWriter(fs)
            Else
                fs = New FileStream(FName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)
                fileWrite = New StreamWriter(fs)
            End If
            fileWrite.Write(vbNewLine & CStr(Now) & ":" & StringtoWrite)
            fileWrite.Close()
            Exit Sub
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try
    End Sub
End Class

Download a File From an URL

Imports System
Imports System.Configuration
Imports System.Resources ' Resource readers
Imports System.Net.WebClient
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim flag As Boolean = False
Dim name As String = ""
Dim number As Integer = 0
Dim FTPC As New System.Net.WebClient
Dim callerFilename As String
Dim Downloadto As String
Dim DownloadtoFolder As String
callerFilename = "default.aspx"
DownloadtoFolder = Application.StartupPath & "\"
Downloadto = DownloadtoFolder & "\" & callerFilename
Dim strURL = "http://www.yourwebsite.in/default.aspx"
MsgBox(strURL)
Dim sysWebClient As System.Net.WebClient = New System.Net.WebClient
If Not Directory.Exists(DownloadtoFolder) Then
Directory.CreateDirectory(DownloadtoFolder)
End If
sysWebClient.DownloadFile(strURL, Downloadto)
End Sub
End Class

Get the name and type of column of a table

   Public sub GetColumns(ByVal sTableName As String, ByVal ListBoxObject As ListView) 
               
                Dim iCount As Integer
                Dim ObjListviewItem As ListViewItem
                Dim sSQL As String = "Select * From " & sTableName & " Where 1 = 2"
                Dim oCmd As Odbc.OdbcCommand = New OdbcCommand(sSQL, ObjCon)               
                Dim oRS As Odbc.OdbcDataReader = oCmd.ExecuteReader
                ListBoxObject.Items.Clear()
                For iCount = 0 To oRS.FieldCount - 1
                    ObjListviewItem = ListBoxObject.Items.Add(oRS.GetName(iCount), 0)
                    ObjListviewItem.SubItems.Add(oRS.GetFieldType(iCount).ToString)
                Next iCount
                oRS.Close()              
            Catch ex As Exception
               msgbox( Err.Description)
            End Try
        End Function
    End Class

List Of Table

 Private sub GetTables(ByVal sDatabaseName As String, ByVal ListBoxObject As ListBox)
            Try
               
                Dim sSQL As String = "show tables in " & sDatabaseName
                Dim oCmd As Odbc.OdbcCommand = ObjCon.CreateCommand
                oCmd.CommandText = sSQL

                Dim oRS As Odbc.OdbcDataReader = oCmd.ExecuteReader
                Do While oRS.Read
                    ListBoxObject.Items.Add(oRS(0))
                Loop
                oRS.Close()
               

            Catch ex As Exception
                msgbox(err.description)
            End Try
     End Function

List of Databse


How To List the Databse

Public sub DatabaseList(ByVal ListBoxObject As Object)
Try
If ObjCon.State = ConnectionState.Open Then
Dim sSQL As String = "show databases"
Dim oCmd As Odbc.OdbcCommand = ObjCon.CreateCommand
oCmd.CommandText = sSQL
Dim oRS As Odbc.OdbcDataReader = oCmd.ExecuteReader
Do While oRS.Read
ListBoxObject.Items.Add(oRS(0))
Loop
oRS.Close()
End If
Catch ex As Exception
msgbox( Err.Description)
End Try
End Function