VB.NET 2003 SOURCE CODE LIBRARY
ASP.NET LOGIN USING VB.NET
ASP.NET USER LOGIN PROJECT USING VB.NET ======================================== LOGIN.ASPX: =========== Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load txtmsg.Visible = False Session("a") = txtun.Text Session("b") = txtupass.Text End Sub Private Sub lnknew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnknew.Click Response.Redirect("newu.aspx") End Sub Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click txtun.Text = "" txtupass.Text = "" txtmsg.Text = "" End Sub Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click OleDbConnection1.Open() Dim com As New OleDbCommand Try txtmsg.Text = Session("a") If txtun.Text = " " Or txtupass.Text = " " Then Response.Redirect("login.aspx") End If OleDbDataAdapter1 = New OleDbDataAdapter("select * from ustbl", OleDbConnection1) OleDbDataAdapter1.Fill(Ds11, "tblusr") Dim dr As OleDbDataReader com.Connection = OleDbConnection1 com.CommandText = "select * from ustbl where uname='" & Session("a") & "'" com.ExecuteNonQuery() dr = com.ExecuteReader If dr.Read() Then Response.Redirect("logg.aspx") Else txtmsg.Visible = True txtmsg.Text = "USER DOES NOT EXIST..!" End If Catch ex As Exception txtmsg.Text = ex.ToString End Try OleDbConnection1.Close() End Sub End Class ============================================================================================================================ NEW USER.ASPX: ============== Private Sub btnreg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnreg.Click OleDbConnection1.Open() Try OleDbDataAdapter1 = New OleDbDataAdapter("select * from ustbl", OleDbConnection1) OleDbDataAdapter1.Fill(Ds11, "ustbl") Session("a") = txtname.Text Session("b") = txtpassword.Text Session("c") = txtfn.Text Session("d") = txtln.Text Dim com As New OleDbCommand com.Connection = OleDbConnection1 com.CommandText = "insert into ustbl(uname, upass, ufn, uln) values ('" & Session("a") & "','" & Session("b") & "','" & Session("c") & "','" & Session("d") & "')" com.ExecuteNonQuery() txtmsg.Text = "RECORD INSERTED SUCCESSFULLY" OleDbDataAdapter1.Update(Ds11, "ustbl") Catch ex As Exception txtmsg.Text = ex.ToString OleDbConnection1.Close() End Try End Sub Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click txtname.Text = "" txtpassword.Text = "" txtfn.Text = "" txtln.Text = "" txtmsg.Text = "" End Sub End Class ============================================================================================================================ LOGG.ASPX: =========== Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load OleDbConnection1.Open() lbluser.Text = Session("a") OleDbConnection1.Close() End Sub Private Sub lnkedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkedit.Click Response.Redirect("edit.aspx") End Sub Private Sub lnksignout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnksignout.Click Session.Abandon() Response.Redirect("signout.aspx") End Sub End Class ============================================================================================================================ EDIT.ASPX: ================= Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load OleDbConnection1.Open() Try lbluser.Text = Session("a") Catch ex As Exception txtmsg.Text = ex.ToString End Try OleDbConnection1.Close() End Sub Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click OleDbConnection1.Open() Try OleDbDataAdapter1 = New OleDbDataAdapter("select * from ustbl", OleDbConnection1) OleDbDataAdapter1.Fill(Ds21, "ustbl") Dim com As New OleDbCommand com.Connection = OleDbConnection1 com.CommandText = "update ustbl set upass='" & txtpassword.Text & "', ufn='" & txtfn.Text & "', uln='" & txtln.Text & "' where uname='" & txtname.Text & "' " com.ExecuteNonQuery() OleDbDataAdapter1.Update(Ds21, "ustbl") txtmsg.Text = "RECORD UPDATED SUCCESSFULLY" Catch ex As Exception txtmsg.Text = ex.ToString OleDbConnection1.Close() End Try End Sub Private Sub lnkmenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkmenu.Click Response.Redirect("logg.aspx") End Sub Private Sub vprofile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vprofile.Click OleDbConnection1.Open() Dim com As New OleDbCommand Try OleDbDataAdapter1 = New OleDbDataAdapter("select * from ustbl", OleDbConnection1) OleDbDataAdapter1.Fill(Ds21, "ustbl") Dim dr As OleDbDataReader com.Connection = OleDbConnection1 com.CommandText = "select * from ustbl where uname='" & Session("a") & "'" com.ExecuteNonQuery() dr = com.ExecuteReader If dr.Read() Then lblname.Visible = True lblpass.Visible = True lblfn.Visible = True lblln.Visible = True lnkmenu.Visible = True txtmsg.Visible = True txtname.Visible = True txtpassword.Visible = True txtfn.Visible = True txtln.Visible = True btnedit.Visible = True txtname.Text = Session("a") txtpassword.Text = Session("b") txtfn.Text = dr("ufn") txtln.Text = dr("uln") Else txtmsg.Text = "Sorry...!You are not a Registered User" End If dr.Close() Catch ex As Exception txtmsg.Text = ex.ToString End Try OleDbConnection1.Close() End Sub End Class ============================================================================================================================ GLOBAL.ASAX: ============= Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started End Sub Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Session("a") = "" Session("b") = "" Session("c") = "" Session("d") = "" End Sub End Class ============================================================================================================================ SIGNOUT.ASPX: ============= Private Sub lnkmain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkmain.Click Response.Redirect("login.aspx") End Sub ============================================================================================================================
INSERTABLE AND EDITABLE DATAGRID EXAMPLE USING VB.NET
INSERTABLE DATAGRID EXAMPLE: =============================
Insert
============================================================================================================================================================ BACK END CODE: =============== Imports System.Data Imports System.Data.OleDb Public Class WebForm1 Inherits System.Web.UI.Page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then BindGrid() End If End Sub Sub BindGrid() OleDbConnection1.Open() OleDbDataAdapter1 = New OleDbDataAdapter("select * from phbook", OleDbConnection1) OleDbDataAdapter1.Fill(DataSet11, "phbook") dg1.DataSource = DataSet11 dg1.DataBind() End Sub Private Sub dg1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg1.ItemCommand If e.CommandName = "Insert" Then Dim t1 As TextBox = e.Item.FindControl("textbox2") Dim t2 As TextBox = e.Item.FindControl("textbox4") Dim t3 As TextBox = e.Item.FindControl("textbox6") OleDbConnection1.Open() Dim com As New OleDbCommand com.Connection = OleDbConnection1 com.CommandText = "insert into phbook(name,phone,address) values('" & t1.Text & "','" & t2.Text & "','" & t3.Text & "')" com.ExecuteNonQuery() OleDbConnection1.Close() BindGrid() End If End Sub End Class ============================================================================================================================================================ EDITABLE DATAGRID EXAMPLE: ========================== Imports System.Data Imports System.Data.oledb Public Class WebForm1 Inherits System.Web.UI.Page Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then BindData() End If End Sub Public Sub BindData() OleDbConnection1.Open() OleDbDataAdapter1 = New OleDbDataAdapter("select * from phbook", OleDbConnection1) OleDbDataAdapter1.Fill(DataSet11, "phbook") dg1.DataBind() OleDbConnection1.Close() End Sub Private Sub dg1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg1.EditCommand dg1.EditItemIndex = e.Item.ItemIndex BindData() End Sub Private Sub dg1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg1.CancelCommand dg1.EditItemIndex = -1 BindData() txtmsg.Text = "" End Sub Private Sub dg1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg1.UpdateCommand //Accessing first column value Dim a = CType(e.Item.Cells(2).Controls(0), TextBox) Dim a1 As String = a.Text lbltext.Text = a1 //Accessing second column value Dim b = CType(e.Item.Cells(3).Controls(0), TextBox) Dim b1 As String = b.Text lbltext1.Text = b1 //Accessing third column value Dim c = CType(e.Item.Cells(4).Controls(0), TextBox) Dim c1 As String = c.Text lbltext2.Text = c1 OleDbConnection1.Open() Try Dim com As New OleDbCommand com.Connection = OleDbConnection1 com.CommandText = "update phbook set name='" & a1 & "', phone='" & b1 & "', address='" & c1 & "' where u_id=" & e.Item.Cells(1).Text com.ExecuteNonQuery() OleDbDataAdapter1.Update(DataSet11, "phbook") txtmsg.Text = "RECORD UPDATED SUCCESSFULLY" Catch ex As Exception txtmsg.Text = ex.ToString OleDbConnection1.Close() End Try End Sub Private Sub dg1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dg1.PageIndexChanged dg1.CurrentPageIndex = e.NewPageIndex BindData() End Sub End Class
DEPLOYING VB.NET APPLICATIONS
Deploying Applications: ======================== Once an application is developed and if we want to distribute that application, we need to deploy that. Deployment is the process where we create an executable file which can be installed on any machine where the application can run. We can use the built-in deployment feature that comes with Visual Basic to create a Windows Installer file - a .msi file for the purpose of deploying applications. Let's look at the process with an example. Let's assume we have a form with a TextBox and a Button. When the Button is clicked the TextBox should display "This application is Deployed". Let's name this application as Deploy. The code for the click event of the Button looks like this: Private Sub Button1_Click(By Val sender as System.Object, By Val e_ as System.EventArgs)Handles Button1.Click TextBox1.Text="This application is Deployed" End Sub Next, we need to create an executable (exe) file for this application. To do that select Build->Build from the main menu which builds Deploy.exe. Next, we need to create an installer file for Deploy (which is the example) which is a file with .msi extension. To do that, select File->Add Project->New Project which opens the new project dialogue. Select "Setup and Deployment Projects" icon in the projects type box and Setup Wizard in the templates box. It looks like the image below. Click OK to open the Setup Wizard. The Setup wizard window looks like the image below. Click next on the above pane to take you to second pane in the Wizard. The new pane allows us to create deployment projects both for Windows and Web Applications. Here, select the radio button which says "Create a setup for Windows Application" as this is deploying a windows application and click next. It looks like the image below. Clicking next opens a new pane which has options like Deploying only primary output from the project or both the project and source code or content files. Check the checkbox which you want, in this case check the checkbox that says "Primary Output from Deploy" and click next. Clicking next opens a new pane which asks if you want any additional files to be added. If you wish, you can include other files, like an icon for the application. In this example don't include any files and click next. It looks like the image below. Doing that brings up the last pane of the Setup Wizard which looks like the image below. Click Finish on this pane. Clicking finish opens up a File System window which looks like the image below. This window allows us to create shortcuts to the application on the desktop and in our Programs Menu. To create a shortcut, right-click on the folder "User's Desktop" and select "Create Shortcut to User's Desktop". Rename the shortcut to "Deployment". If we want a shortcut to the application from our Programs Menu, right-click on "User's Program Menu" folder and select "Create Shortcut to User's Program Menu". Rename the shortcut to "Deployment". Once you are finished with it, click on "Application Folder" and open it's properties. In the properties window set the property "Always Create" to True. Set the same for "User's Desktop" and "User's Programs Menu" folders. If you want any additional information to include with the set-up project, like the manufacturer, author etc, click on Setup1 project and open it's properties. You can set additional information here. Once your are done with it build the project by right-clicking on Setup1 and selecting Build. This builds the application. The setup file is created in the debug folder of Setup1 project. To deploy the application we need to copy Setup1.msi file to the target machine. Once copying is done, double-click that file which opens the Windows Installer which is a new window which says "Welcome to Setup1 Setup Wizard". It looks like the image below (mine was Setup7, yours will be Setup1). Click next to move to next window which allows us to specify the location where the application should be installed. It looks like the image below. Select the location for installation and click next. Clicking next installs the application. The confirmation window looks like the image below. Now, double-click the newly installed Deployment.exe file to run and get the desired result. You can select that from your Programs Menu or Desktop. That completes the process of Deploying Applications.Make sure the Target Machine on which the application will be installed supports Windows Installer and .NET Framework.
VB.NET MOBILE CODES
VB.NET MOBILE CODES ===================================================================== Listing 16.1 (1601.wml) Simple WML Application
Hello Mobile Device User
===================================================================== Listing 16.2 An Example of a Simple Mobile Form-Based Application <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="vb" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
Form One
Form Two
===================================================================== Listing 16.3 Mobile:Label Example
Text
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="vb" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
More Text
Text
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="C#" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
This is an example of a mobile:TextView control!
===================================================================== The Mobile:Image Control The syntax of the Mobile:Image control is as follows:
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="C#" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
Open Folder
Closed Folder
===================================================================== The Mobile:Panel Control The syntax of a Mobile:Panel control is as follows:
... Controls inside Panel Control go here
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="c#" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
First Panel
is up here
Second Panel here
The Mobile:StyleSheet Control The syntax of the Mobile:StyleSheet control is as follows:
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="C#" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
This is Style 1
This is Style 2
===================================================================== The Mobile:Link Control The syntax of the Mobile:Link control is as follows:
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="C#" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
123 Jump WAP Portal
===================================================================== The Mobile:Command Control The syntax of the Mobile:Command control is as follows:
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="vb" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
Enter First Name
Enter Last Name
OK
The Mobile:TextBox Control The syntax of the Mobile:TextBox control is as follows:
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="vb" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
Enter your name
Enter your password
Enter your Bank Balance
OK
===================================================================== The Mobile:List Control The Mobile:List control can be used to render a list of items to the mobile device user. These are either static or loaded into the control from a data source. The syntax of the Mobile:List control is as follows:
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="vb" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
===================================================================== Listing 16.12 Databound Mobile:List Example <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="vb" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <%@ import namespace="System.Data.SqlClient" %>
Select Employee
===================================================================== Set phone number for mobile phone (VB.net) <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
WAP - WML -WMLSCRIPT EXAMPLES
WAP - WML - WMLSCRIPT EXAMPLES ===================================================================== Visit Website for all the codes, examples and refrences http://www.developershome.com
WORD EDITOR WITH MENU USING VB.NET
Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form Dim strfn As String Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click Me.Close() End Sub Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click txteditor.Text = "" End Sub Private Sub MenuItem15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem15.Click txteditor.Text = Now() End Sub Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click With OpenDialog .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" .FilterIndex = 1 .InitialDirectory = "c:\" .Title = "Open" End With If OpenDialog.ShowDialog() = DialogResult.OK Then strfn = OpenDialog.FileName Dim srd As StreamReader = New StreamReader(strfn) txteditor.Text = srd.ReadToEnd() srd.Close() srd = Nothing End If End Sub Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click txteditor.Text = "" End Sub Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click With SaveDialog .DefaultExt = "txt" .FileName = strfn .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" .FilterIndex = 1 .InitialDirectory = "c:\" .OverwritePrompt = True .Title = "Save" If SaveDialog.ShowDialog = DialogResult.OK Then strfn = SaveDialog.FileName Dim swr As StreamWriter = New StreamWriter(strfn, False) swr.Write(txteditor.Text) swr.Close() swr = Nothing End If End With End Sub Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click Dim txt As TextBox = Me.ActiveControl txteditor.Cut() End Sub Private Sub MenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem10.Click Dim txt As TextBox = Me.ActiveControl txteditor.Copy() End Sub Private Sub MenuItem11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem11.Click Dim txt As TextBox = Me.ActiveControl txteditor.Paste() End Sub Private Sub MenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem13.Click Dim txt As TextBox = Me.ActiveControl txteditor.SelectAll() End Sub Private Sub MenuItem19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem19.Click If FontDialog.ShowDialog = DialogResult.OK Then txteditor.Font = FontDialog.Font End If End Sub Private Sub MenuItem17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem17.Click ColorDialog.ShowDialog() txteditor.ForeColor = ColorDialog.Color End Sub SELECT IMAGE FROM HARD DRIVE AND DISPLAY IT IN THE PIC BOX: =========================================================== Private Sub btnselect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnselect.Click With OpenDialog .Filter = "All Files |*.*| Bitmaps |*.bmp| GIFS| *.gif| JPEGS| *.jpg" .InitialDirectory = "c:\" .FilterIndex = 2 End With If OpenDialog.ShowDialog() = DialogResult.OK Then picbox.Image = Image.FromFile(OpenDialog.FileName) picbox.SizeMode = PictureBoxSizeMode.CenterImage lblfname.text = OpenDialog.FileName End If End Sub End Class
SENDING E-MAIL USING VB.NET
Imports system.web.mail Imports system.web.mail.SmtpMail Public class webform1 Inherits System.web.UI.Page Private sub btnsend_Click(ByVal sender As system.Object, ByVal e As System.EventArgs) Handlesbtnsend.Click Dim ObjMail As New MailMessage dim a as MailAttachment = New MailAttachment("C:\a.jpg") objMail.Attachments.Add(a) Try objMail = New MailMessage objMail.BodyFormat = MailFormat.Text objMail.To = txtto.Text objMail.From = txtfrom.Text objMail.Subject = txtsubject.Text objMail.Body = txtbody.Text SmtpMail.SmtpServer = "127.0.0.1" SmtpMail.Send(objMail) lblmsg.Text="OK" Catch ex as Exception Dim mm as String = ex.Message.ToString lblmsg.Text = mm End Try End Sub End Class
FOUR FUNCTION CALCULATOR USING VB.NET
FOUR FUNCTION CALCULATOR USING VB.NET: ======================================= Public Class Form1 Inherits System.Windows.Forms.Form Dim cval As Double //current value Dim operator As Char //operator to be used Dim opressed As Boolean //pressed or not Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click Me.Close() End Sub Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click txtanswer.Text = txtanswer.Text & "1" End Sub Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click txtanswer.Text = txtanswer.Text & "2" End Sub Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click txtanswer.Text = txtanswer.Text & "3" End Sub Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click txtanswer.Text = txtanswer.Text & "4" End Sub Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click txtanswer.Text = txtanswer.Text & "5" End Sub Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click txtanswer.Text = txtanswer.Text & "6" End Sub Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click txtanswer.Text = txtanswer.Text & "7" End Sub Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click txtanswer.Text = txtanswer.Text & "8" End Sub Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click txtanswer.Text = txtanswer.Text & "9" End Sub Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click If txtanswer.Text = "" Then btn0.Enabled = True Else txtanswer.Text = txtanswer.Text & "0" End If End Sub Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click txtanswer.Text = "" End Sub Private Sub btnpm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpm.Click txtanswer.Text = Val(txtanswer.Text) * -1 End Sub Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click opressed = True operator = btnadd.Text If opressed Then cval = Val(txtanswer.Text) txtanswer.Text = "" opressed = False End If End Sub Private Sub btnequal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnequal.Click Select Case operator Case "+" txtanswer.Text = cval + Val(txtanswer.Text) Case "-" txtanswer.Text = cval - Val(txtanswer.Text) Case "*" txtanswer.Text = cval * Val(txtanswer.Text) Case "/" txtanswer.Text = cval / Val(txtanswer.Text) End Select End Sub Private Sub btnminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnminus.Click opressed = True operator = btnminus.Text If opressed Then cval = Val(txtanswer.Text) txtanswer.Text = "" opressed = False End If End Sub Private Sub btnmul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmul.Click opressed = True operator = btnmul.Text If opressed Then cval = Val(txtanswer.Text) txtanswer.Text = "" opressed = False End If End Sub Private Sub btndiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndiv.Click opressed = True operator = btndiv.Text If opressed Then cval = Val(txtanswer.Text) txtanswer.Text = "" opressed = False End If End Sub Private Sub btn1x_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1x.Click txtanswer.Text = 1 / Val(txtanswer.Text) End Sub Private Sub btnpercen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpercen.Click txtanswer.Text = (cval / Val(txtanswer.Text)) * 100 End Sub Private Sub btnsqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsqrt.Click txtanswer.Text = Math.Sqrt(Val(txtanswer.Text)) End Sub Private Sub btnbspace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbspace.Click If Len(txtanswer.Text) > 0 Then txtanswer.Text = Strings.Left(txtanswer.Text, Len(txtanswer.Text) - 1) End If End Sub End Class
VB.NET CRYSTAL REPORTS IN WINDOWS & WEB FORMS:
CRYSTAL REPORT VIEWER IN VB.NET (WINDOWS FORM): =============================================== =>drag crystal report viewer to windows form and add the following code: =>dim rpt as New CrystalReport2-(crystal report name) =>rpt.SetDataSource(dataset name) =>crv1.reportsource=rpt (crv1 is the crystal report viewer name)
CRYSTAL REPORT VIEWER IN VB.NET (WEB FORM): =========================================== =>drag crystal report viewer to the web form =>add new crystal report to the web form (NOW ADD THE CODE) =>dim crp as CrystalReport1 =>private sub page_load(by val) =>crp=new crystalReport1 =>crv1.ReportSource=crp
PHONE BOOK WITH SEARCHING FACILITY USING VB.NET:
PHONE BOOK WITH SEARCHING FACILITY USING VB.NET: =============================================== Imports System.Data Imports System.Data.OleDb Public Class WebForm1 Inherits System.Web.UI.Page Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click Try txtmsg.Text = "" OleDbDataAdapter1 = New OleDbDataAdapter("select * from phbook where name like '" & ddl.SelectedItem.Text & "%'", OleDbConnection1) OleDbDataAdapter1.Fill(DataSet21, "phbook") OleDbConnection1.Open() Dim com As New OleDbCommand com.Connection = OleDbConnection1 com.CommandText = "select * from phbook" dg1.DataBind() Catch ex As Exception txtmsg.Text = ex.ToString OleDbConnection1.Close() End Try End Sub Private Sub dg1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dg1.SelectedIndexChanged txtname.Text = dg1.SelectedItem.Cells(1).Text txtphone.Text = dg1.SelectedItem.Cells(2).Text txtaddress.Text = dg1.SelectedItem.Cells(3).Text End Sub Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click OleDbConnection1.Open() Try Dim com As New OleDbCommand com.Connection = OleDbConnection1 com.CommandText = "update phbook set phone='" & txtphone.Text & "',address='" & txtaddress.Text & "' where name='" & txtname.Text & "'" com.ExecuteNonQuery() OleDbDataAdapter1.Update(DataSet21, "phbook") txtmsg.Text = "RECORD UPDATED SUCCESSFULLY" Catch ex As Exception txtmsg.Text = ex.ToString OleDbConnection1.Close() End Try End Sub Private Sub dg1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dg1.PageIndexChanged dg1.CurrentPageIndex = e.NewPageIndex OleDbDataAdapter1.Fill(DataSet21, "phbook") dg1.DataBind() End Sub End Class
DATABINDING EXAMPLE USING VB.NET
DATABINDING EXAMPLE USING VB.NET: ================================= Imports System.Data Imports System.Data.oledb Public Class Form1 Inherits System.Windows.Forms.Form Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click OleDbConnection1.Open() OleDbDataAdapter1 = New OleDbDataAdapter("select * from phbook", OleDbConnection1) OleDbDataAdapter1.Fill(DataSet11, "phbook") txtrecnum.Text = Me.BindingContext(DataSet11, "phbook").Position + 1 & " OF " & Me.BindingContext(DataSet11, "phbook").Count OleDbConnection1.Close() End Sub Private Sub btnnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnew.Click txtid.Text = "" txtname.Text = "" txtphone.Text = "" txtaddress.Text = "" End Sub Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click Me.Close() End Sub Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click Me.BindingContext(DataSet11, "phbook").Position = Me.BindingContext(DataSet11, "phbook").Position + 1 txtrecnum.Text = Me.BindingContext(DataSet11, "phbook").Position + 1 & " OF " & Me.BindingContext(DataSet11, "phbook").Count End Sub Private Sub btninsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btninsert.Click OleDbConnection1.Open() Try Dim com As New OleDbCommand com.Connection = OleDbConnection1 com.CommandText = "insert into phbook(name, phone, address)values('" & txtname.Text & "','" & txtphone.Text & "','" & txtaddress.Text & "') " com.ExecuteNonQuery() OleDbDataAdapter1.Update(DataSet11, "phbook") MsgBox("RECORD INSERTED SUCCESSFULLY") Catch ex As Exception MsgBox(ex.ToString) OleDbConnection1.Close() End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OleDbConnection1.Open() Try Dim com As New OleDbCommand com.Connection = OleDbConnection1 com.CommandText = "update phbook set name='" & txtname.Text & "', phone='" & txtphone.Text & "', address='" & txtaddress.Text & "' where u_id=" & txtid.Text & "" com.ExecuteNonQuery() OleDbDataAdapter1.Update(DataSet11, "phbook") MsgBox("RECORD UPDATED SUCCESSFULLY") Catch ex As Exception MsgBox(ex.ToString) OleDbConnection1.Close() End Try End Sub Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click Me.BindingContext(DataSet11, "phbook").Position = 0 txtrecnum.Text = Me.BindingContext(DataSet11, "phbook").Position + 1 & " OF " & Me.BindingContext(DataSet11, "phbook").Count End Sub Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click Me.BindingContext(DataSet11, "phbook").Position = Me.BindingContext(DataSet11, "phbook").Position - 1 txtrecnum.Text = Me.BindingContext(DataSet11, "phbook").Position + 1 & " OF " & Me.BindingContext(DataSet11, "phbook").Count End Sub Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlast.Click Me.BindingContext(DataSet11, "phbook").Position = Me.BindingContext(DataSet11, "phbook").Count - 1 txtrecnum.Text = Me.BindingContext(DataSet11, "phbook").Position + 1 & " OF " & Me.BindingContext(DataSet11, "phbook").Count End Sub End Class
VB.NET 2005 SOURCE CODE LIBRARY
CONVERTING IMAGES TO THUMBNAIL AND SAVING PATH TO DATABASE
Imports system.data Imports system.data.SqlClient Imports System.Drawing Imports System.Drawing.Imaging Imports System.Drawing.Drawing2D Imports System.IO Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click 'UPLOADING IMAGE FILES TO GET FILE NAME AND FOLDER RELATIVE PATH '================================================================ Dim file_name As String Dim input_image1 As Image file_name = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName) input_image1 = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream) FileUpload1.SaveAs(Server.MapPath("img_files/index.html") & file_name) Dim db As String db = "img_files/" & file_name 'CONVERTING IMAGE TO THUMBNAIL '============================= Dim input_image, thumbnail As Image input_image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream) thumbnail = input_image.GetThumbnailImage(100, 100, Nothing, Nothing) thumbnail.Save(Server.MapPath("img_files/Thumb/index.html") & file_name) 'INSERTING IMAGE TO DATABASE '=========================== Dim sqlcon = New SqlConnection("Data Source=pc7;Initial Catalog=Members;User ID=sa") Dim com As New SqlCommand Dim brand = txtimg_name.Text Dim sort = txtsort_order.Text Try sqlcon.Open() com.Connection = sqlcon com.CommandText = "insert into tblBrands(brand_name, brand_logo, sort_order)values ('" & brand & "','" & db & "','" & sort & "')" com.ExecuteNonQuery() lblmsg.Text = "BRAND INFO INSERTED SUCCESSFULLY" Catch ex As Exception lblmsg.Text = ex.ToString sqlcon.close() End Try End Sub End Class
IMAGE CROP
Imports System.Drawing Imports System.Drawing.Imaging Imports System.Drawing.Drawing2D Protected Sub btncrop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncrop.Click 'get original bitmap Dim file_name As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName) Dim original_Image As System.Drawing.Image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream) 'create thumbnail from the original bitmap Dim Cropped As New Bitmap(100, 100) Dim myGraphic As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(Cropped) 'crop to the graphic object from the original bitmap myGraphic.DrawImage(original_Image, New Rectangle(0, 0, Cropped.Width, Cropped.Height), 100, 100, Cropped.Width, Cropped.Height, GraphicsUnit.Pixel) myGraphic.Dispose() 'Set the content type Response.ContentType = "image/jpeg" 'send the cropped image to the outputstream Cropped.Save(Response.OutputStream, ImageFormat.Jpeg) Cropped.Save(Server.MapPath("img_files/index.html") & file_name) 'tidy up original_Image.Dispose() Cropped.Dispose() End Sub
VB 2005 SqlConnection Class
CONNECT.VB: ----------- Imports System.Data.SqlClient Public Class connection_string Public Shared sqlCon As SqlConnection Public Sub New() End Sub Public Shared Function EstablishConnection() As SqlConnection sqlCon = New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings( "pubsConnectionString").ToString) sqlCon.Open() Return sqlCon End Function Public Shared Function CloseConnection() sqlCon.Close() Return sqlCon End Function Public Shared Function disposeConnection() sqlCon.Dispose() Return sqlCon End Function End Class WEB.CONFIG: -----------
CODE FILE: ---------- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load connection_string.EstablishConnection() Dim Str As String = "SELECT * FROM authors" Dim Com As New SqlCommand(Str, connection_string.sqlCon) Dim ds As New DataSet Dim da As New SqlDataAdapter(Com) da.Fill(ds) GridView1.DataSource = ds GridView1.DataBind() connection_string.CloseConnection() End Sub