welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Monday, January 31, 2011


Hi ...In this article i am going to describe about the loop, what we are oftenly used in VB.NET

In intially there are two basic kinds of loop

■ While loops, also called Do loops

■ For loops, including For Next and For Each

A While loop is the simplest form of loop  it makes a block of code repeat for as long as a particular condition is true. Here’s an example:

Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
Dim counter As Integer = 0
Do While t1 <= 10
messageLabel.Text = counter.ToString()
t1 += 1
End Sub

In this examble when the page load its dislplay the number 10,,which will increment to 1, then 2, all the way to 10.

The other form of the While loop, called a Do While loop
Exanble for Do while loop,In the do while loop the condition has met at the end of the code....
Sub Page_Load(s As Object, e As EventArgs)
Dim counter As Integer = 0
messageLabel.Text = counter.ToString()
counter += 1
Loop While counter <= 10
End Sub


A For loop is similar to a While loop, but we typically use it when we know in advance
how many times we need it to execute.....

Dim i As Integer
For i = 1 To dropdownList.Items.Count
messageLabel.Text = i.ToString()

It will diplay the items present in the dropdownlist box...

And other type of forloop is FOR EACH
There is a main difference betwen FOR and FOR EACH loop
in for loop its start with predefined intial  value and end with maximum value so its represent mostly integer but For each loop variable represents the object from the collection ,it may be integer,string or date.
For an examble we can looping in array it contains the string value, loop contine upto the last item in the arrya....

For Each item In arrayName
messageLabel.Text = item

Let me discuss one another examble to clearly understand the concept of FOR EACH

For Each num As String In ComboBox1.Items


Let us see in this examble. we are loading the combobox item into listbox using FOR EACH loop,This loop will continue upto the item present in combobox...

i hope this article would help you  to get clear idea about  loops...

Friday, January 28, 2011

Ajax and Update pannel

hi..friends here i penned about the today popular buzz AJAX in web development. i know so many folks dont know the correct usage of ajax,AJAX terms asynchronous javascript and xml, Ajax is universal one,you can use this ajax in php,vb,c# and and  many programming lanuages
Ajax has been used in popular search engine google,In google you can find ,when you are strat to type a message it show some  related result in a box,how it happen by using ajax.
everytime it get request from the server without refreshing the whole page, this process can be achived by using update panel.
In an update panel one more function was there ,i.e trigger,many folks dont know the proper function of trigger..By using trigger we can fire a button from an outside the update panel ,thats is no need to kept the button inside the pannel,we can  call the button using trigger....see the examble you can easily understand the process of update panel

In this coding you can watch i kept the button outside the update panel, here by using AsyncPostBackTrigge we fire the button
client side coding:
Here you have to add BUtton,Textbox,update panel and script manager.
''<table cellpadding="0" cellspacing="0" align="center" width="500">

''<asp:Button ID="buttonclick" runat="server" Text="click1" />
   '' <asp:ScriptManager ID="ScriptManager1" runat="server">
    ''<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    ''<ContentTemplate >
        ''<asp:TextBox ID="txthello" runat="server"></asp:TextBox>
    ''<asp:AsyncPostBackTrigger ControlID ="buttonclick" EventName ="click" />
    '' </Triggers>
server side coding:

  Protected Sub buttonclick_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonclick.Click
        txthello.Text = "using trigger"
    End Sub

i hope this blog will helpful to know about AJAX usage....
plz post your valoable commnets here...

Monday, January 24, 2011


hi friends......

i knew many peoples are googled to find the solution fot this problem...
i hope this code will be digest your problem....
for that first you create one table in sql databse like this

subject  varchar(50) NULL,int NULL,
mark1 int NULL,
mark2 int NULL

And then create table in excel sheet ..... subject mark1 mark2 maths 50 70 english 56 89 server side coding.... In the button field add the following coding... Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim filepath As String = "C:\Markt.xls" version = Mid(filepath, filepath.LastIndexOf(".") + 1, 5) Try If version = ".xls" Then 'Execute when MS EXCEL 2003 Format Dim MyConnection As System.Data.OleDb.OleDbConnection Dim DtSet As System.Data.DataSet Dim MyCommand As System.Data.OleDb.OleDbDataAdapter MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & filepath & "';Extended Properties=Excel 8.0;") MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection) DtSet = New System.Data.DataSet MyCommand.Fill(DtSet, "[Sheet1$]") dt = DtSet.Tables(0) MyConnection.Close() ElseIf version = ".xlsx" Then 'Execute when MS EXCEL 2007 Format Dim MyConnection As System.Data.OleDb.OleDbConnection Dim DtSet As System.Data.DataSet Dim MyCommand As System.Data.OleDb.OleDbDataAdapter MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & filepath & "';Extended Properties=Excel 12.0;") MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection) DtSet = New System.Data.DataSet MyCommand.Fill(DtSet, "[Sheet1$]") dt = DtSet.Tables(0) MyConnection.Close() Else Label1.Text = "This Version is not Support!" Exit Sub End If If dt.Rows.Count > 0 Then For i = 0 To dt.Rows.Count - 1 dr = dt.Rows(i) fetch = "insert into StudentList(Regno,Sname,Class) values(" fetch += "'" & dt.Rows(i).Item(0) & "'," fetch += "'" & dt.Rows(i).Item(1) & "'," fetch += "'" & dt.Rows(i).Item(2) & "')" sqlcmd = New SqlCommand(fetch, sqlcon) sqlcmd.CommandType = CommandType.Text sqlcmd.ExecuteNonQuery() fetch = "" Next Label1.Text = "successfully Imported values to SQL Server" End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class

Thursday, January 20, 2011

Read your file from your harddisk and store into Database


Now in this article you are going to see about to read file from your hard disk and load into database. Article we are using function  streamreader

By using streamreader,and string,readline()  helps to read all the text fromt the file
check this code and try yourself with your own project............

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

ProgressBar1.Minimum = 0
        ProgressBar1.Maximum = 1000
        ProgressBar1.Value = 1000
        Dim str As New StreamReader("C:\Users\admin\Desktop\notes.txt")
        Dim text As String
        Dim text2 As String
        text = str.ReadLine()
        Do Until text Is Nothing

            text = str.ReadLine()
            'If ProgressBar1.Value <= 10000 Then



    End Sub

check it and post your comments.....

Send email by using coding

hi folks...
This is a easy way to send a mail using vb coding...its very simple try this code & send you first email through

First you have to import the namespace for send the mail

 Dim log As String = " "
        Dim content As String = "This is my first mail using"
        Dim mail As MailMessage = New MailMessage()

        mail.To.Add("add sender email address")
        mail.From = New MailAddress(" your email address")
        mail.Subject = "Email using Gmail"

        mail.Body = content

        mail.IsBodyHtml = True
        Dim smtp As SmtpClient = New SmtpClient()
        smtp.Host = ""
        smtp.Credentials = New System.Net.NetworkCredential("your gmail username", " gmail password")
        smtp.EnableSsl = True
        Label1.Text = "your mail has sent"
        Catch ex As Exception
            Label1.Text = "The email cannot be sent" + ex.ToString()
        End Try

Wednesday, January 19, 2011


HI  friends .....
i knew so many of them looking for the solution this problem..........

Generally we all know one method to avoid this problem thats is setting seperate field in that user table,if the user enter the particular field can change in that table ,when log out agin the field comes to defaut value....But in this method we have one proble suppose the user exists apprpriately without clicking log out that is(close browser directly )..then the field cannot change ...

Next time when the user enter ..its show error avoid this problem simply we have to follow addtional methods..that is we have to add session status..In that session status we have add the change query,we have to find the session state in GLOBAL.ASAX file ,in that file you have to add session state

Here the process to find GLOBAL>ASAX file...Right click ADD NEW ITEM--GLOBAL.ASAX FILE

 Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        Dim fselect As String
              select = "update Login1 set status='N' where UserId='" & Session("Username") & "'"
     sqlcmd = New SqlCommand(select, sqlcon)
end sub

Also you add follow one more steps......
In that web config file you have add the session time out....

            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.

            Visual Basic options:
            Set strict="true" to disallow all data type conversions 
            where data loss can occur. 
            Set explicit="true" to force declaration of all variables.
    <!--<sessionState mode="StateServer" stateConnectionString=""  cookieless="false" timeout="1" />-->
    <sessionState mode="InProc" timeout ="1">
    <compilation debug="true" strict="false" explicit="true">

Now you can run the process.........
Even the user not properly exit also that table can change the value......

Further if you have any doubt contact me...i am looking forward your comments...