Showing posts with label .NET Apps. Show all posts
Showing posts with label .NET Apps. Show all posts

Saturday 7 September 2013

Access database with vb.net


Microsoft Access database is a Database Management System developed By Microsoft and it is very simple and easy to use for windows application and web application development with Dotnet . Platform. . It supports Microsoft Jet Database Engine . It supports Graphical User Interface with Professional Development tools.

Microsoft is well supported database to be used in Microsoft Visual Studio to develop applications. It is very easy to connect .net either vb.net or C#.net application with Microsoft Access Database

DOWNLOAD this Demo Project from my gmail upload link :-


Steps to Make Microsoft Access Database:

1. Go to desired location you want to make your Database
2. Right click then click on new and 
3. Then click Microsoft Access 2007 Database
4. Create Desired Table with required Fields 
5. Save it as Microsoft Access database 2003 format 
6. click ok 

DOWNLOAD THIS Demo Database from my gmail upload link :-

Steps To Make This Demo Project :-


1. Start your Visual Studio 2010 
2. At start page click on Create New Project 
3. In Dialog Box provide Project name and path where to save this project and click ok
4. Now from Toolbox Drag four Textboxes 
5. Drag 1 Button and make design as show in below image

Design of Form 1 



6. Now copy the code given in code section below :-


Code of Form1



Imports System.Data.OleDb

Public Class Form1

    Dim connection As New OleDbConnection
    Dim command As New OleDbCommand
    Dim ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\test.mdb"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        command.CommandText = "insert into info_table values (" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text & ")"
        command.CommandType = CommandType.Text
        command.Connection = connection
        command.ExecuteNonQuery()
        MsgBox("Record inserted ")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        connection.ConnectionString = ConnectionString
        connection.Open()
    End Sub

End Class


Explanation of Code


Imports System.Data.OleDb


This line of code tells we are importing Oledb Namespace. Oledb stands for Object Linking and Embedding . For using Access database with .net applications we have to inherit classes from this oledb Namespace . Oledb Namespace contains all classes that are required to connect vb.net/c# application to Microsoft Access
Database




Public Class Form1
    Dim connection As New OleDbConnection
    Dim command As New OleDbCommand
    Dim ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\test.mdb
End Class


Now In These lines of code we declared 3 things
1. OledbConnection :- OledbConnection is a class contained in System.Data.Oledb Namespace and it is used to make connectivity to Access Database . It receives the connection string that tells the path of Microsoft Access Database to connect to it. In this line of code we have created instance of Oledbconnection class

2. OledbCommand :- OledbCommand is a class contained in S
ystem.Data.Oledb Namespace and it is used to define or specify the command that we are going to execute on Microsoft Access Database. In this line of code we are creating instance of OledbCommand to use this instance in further code

3. Connection string :- Now we are creating a variable named connectionString that will receive the string or path that tell how we connect to our Access database. It receives two parameters :-

Provider=Microsoft.Jet.OLEDB.4.0 -- 
Data Source=" & "C:\test.mdb

Now Provider is main part here in connection string . Provider is different for different approaches used for connecting data to database . The Connection string contains information that the Provider needs to know to connect to database Once connected then rest of job is done by provider


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        connection.ConnectionString = ConnectionString
        connection.Open()
    End Sub

Now in this block of code we have initialized our OledbConnection instance with connection string variable that we have initialized in previous step. So in this code we have given the Oledbconnectin instance means connection some information about Provider to use and location of database file on computer

Then we have used connection.open() method opens port for Enter into Access Database. this opens a pipe to execute query in database 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        command.CommandText = "insert into info_table values (" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text & ")"
        command.CommandType = CommandType.Text
        command.Connection = connection
        command.ExecuteNonQuery()
        MsgBox("Record inserted ")
    End Sub

Now at last we have used insert query that is coded on Button Click Event . In this code I have told which commandtext to choose and what will be commandType test or storeprocedure . and also we have initialized the command with Oledbconnection instance. Then we have execute command using ExecuteNonQuery() method. This method returns the number of rows affected the database

Delete Record from Access Database

Wednesday 4 September 2013

Text-To-Speech .NET

This post is to introduce you with SAPI that allows a user to make an automated system that will send the input given by user to speakers and then Speakers will speak or output that text

* SAPI Stands for Speech Application Programming Interface . It is an API developed by Microsoft
to allow users to develop speech recognition systems. 

* The first version of SAPI was released in 1995. This is a program that offers Text-To-Speech and speech Recognition Capabilities. 

* SAPI interfaces are provided for C,C++,C# and visual Basic Languages. 

* SAPI is most widely used application program interface ( API ) used today

CODE For Text - To - Speech in  VB.NET 


Dim SAPI
SAPI = CreateObject ( "sapi.spvoice" ) 
SAPI.speak( TextBox2.Text )

In order to Use SAPI we have to create object of SAPI . In Code Above in line 2 we have created object assigned it SAPI . SAPI is a simple variable nothing more than that there is no need to be confused about that . Then we have used speak ( )  method to give or direct the input to speakers to speak or output all given input.


DEMO APPLICATION FOR SAPI

DEMO APPLICATION 1


DOWNLOAD DEMO APPLICATION FROM LINK BELOW


CODE  FOR DEMO APPLICATION :- 


Public Class Form1

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

        Dim i As Integer
        i = 0
        Dim ch As Char
        ch = e.KeyChar

        If ch = " " Then
            Dim SAPI
            SAPI = CreateObject("sapi.spvoice")
            SAPI.speak(TextBox2.Text)
            TextBox2.Text = ""

        Else
TextBox2.text = TextBox2.text + ch;
        End If

    End Sub

Explanation Of Code

In this code I have taken a variable i of type integer and initialized it to Zero . I have taken a  char type variable that will take character typed or cached by keypress event. 

First in If ( ) codition  i have checked whether the entered character is a blank space or not .If entered character is not a blank space then this code just add the entered character to the TextBox and If user has pressed a space then the complete word will be spoken by SAPI object .

This code spoke the words not only characters entered by user it first takes the characters and then collect them and after completion of word it passes it to SAPI object and SAPI will give that word as output to speaker to spoke it

DEMO APPLICATION 2


DOWNLOAD DEMO APPLICATION 2 FROM LINK BELOW




DEMO APPLICATION 3


DOWNLOAD DEMO APPLICATION 3 FROM LINK BELOW
https://docs.google.com/file/d/0ByR2IblIaEGyOGpuT0NiaTZIZHM/edit



Sunday 1 September 2013

Make calculator in .net

There are number of calculators available . If you want to make a Basic calculator in .NET Then you can surf a number of Calculators code on the Internet . But If you have used the calculators come in Microsoft-Windows PC's Then you can notice these are best , easy to operate and can accept no of operators one time as these are advanced calculators . So make a calculator similar to these calculators come in Microsoft-Windows PC's is logical way of developing a calculator. I have tried a simple calculator That only does Addition , Substration, Division and Multiplication of integers and Fractional numbers .

Tuesday 2 July 2013

Date Difference Am to Pm Visual Basic.NET


Instructions To Operate Date Difference Am to Pm 

* First Enter Date 'Hr', 'Min' and 'Sec' TextBox In First Row
* Also Choose "Am/Pm" from ComboBox In first Row
* Now Put Check Mark on  "Submit checkbox "
* Similarly Enter 'Hr', 'Min' and 'Sec' TextBox In Second Row
 * Choose "Am/Pm" from ComboBox In Second Row
* Then click on Submit checkbox in second Row

NOTE :- It is must to Click on Submit ChekBox After Entering Data at Respective Rows

* Finally click on "Get Date diff" Button .


Download Date Difference Am to Pm App

Download Date diff

Working Date Difference Am to Pm :-

1. In Fig.1 you can see the structure of Date diff App.

 . 


2. It also consist of combo Box To select Am/Pm Time . 



 3. After filling values in Text Boxes Its necessary to put check mark on check box "submit" .
 It display date entered .

 4. Finally click on Button Get date diff and it display date on Date-Diff labelled textboxes.

 CODE FOR Date Difference Am to Pm 


 
Public Class Form1
    Public gethr, getmin, getsec, gethr1, getmin1, getsec1, total1, total2, finaltotal, hr1, hr2, diffhr, min1, sec1 As Integer
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            TextBox10.Text = TextBox10.Text + "-" + TextBox1.Text + "-" + TextBox2.Text + "-" + TextBox3.Text + "-" + ComboBox1.SelectedText
            gethr = Val(TextBox1.Text.ToString)
            getmin = Val(TextBox2.Text.ToString)
            getsec = Val(TextBox3.Text.ToString)
            total1 = (gethr * 3600) + (getmin * 60) + (getsec)
        End If
    End Sub
    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then
            TextBox11.Text = TextBox11.Text + "-" + TextBox4.Text + "-" + TextBox5.Text + "-" + TextBox6.Text + "-" + ComboBox2.SelectedText
            gethr1 = Val(TextBox4.Text.ToString)
            getmin1 = Val(TextBox5.Text.ToString)
            getsec1 = Val(TextBox6.Text.ToString)
            total2 = (gethr1 * 3600) + (getmin1 * 60) + (getsec1)
            If ComboBox1.SelectedIndex = 0 And ComboBox2.SelectedIndex = 1 Then
                total1 = total1 + 12 * 3600
            ElseIf ComboBox1.SelectedIndex = 1 And ComboBox2.SelectedIndex = 0 Then
                total1 = total1 + 12 * 3600
            ElseIf ComboBox1.SelectedIndex = 0 And ComboBox2.SelectedIndex = 0 Then
                total1 = total1
            ElseIf ComboBox2.SelectedIndex = 0 And ComboBox1.SelectedIndex = 0 Then
                total1 = total1
            End If
            finaltotal = (Math.Abs(total1 - total2))
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add("Am")
        ComboBox1.Items.Add("Pm")
        ComboBox2.Items.Add("Am")
        ComboBox2.Items.Add("Pm6")
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If finaltotal <= 60 Then
            TextBox7.Text = "0"
            TextBox8.Text = "0"
            TextBox9.Text = Math.Floor(finaltotal)
        ElseIf finaltotal > 60 And finaltotal < 3600 Then
            TextBox7.Text = "0"
            TextBox8.Text = Math.Floor(finaltotal / 60)
            TextBox9.Text = Math.Floor(finaltotal Mod 60)
        ElseIf finaltotal >= 3600 Then
            hr1 = Math.Floor(finaltotal / 3600)
            TextBox7.Text = hr1
            hr2 = hr1 * 3600
            diffhr = finaltotal - hr2
            min1 = Math.Floor(diffhr / 60)
            TextBox8.Text = min1
            sec1 = finaltotal Mod 60
            TextBox9.Text = sec1
        End If
    End Sub
End Class