Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,027 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,558 people online right now. Registration is fast and FREE... Join Now!




connecting access database to vb.net and validation

 
Reply to this topicStart new topic

connecting access database to vb.net and validation

prads
24 Feb, 2008 - 04:25 PM
Post #1

D.I.C Head
**

Joined: 22 Oct, 2007
Posts: 111


My Contributions
Hello,
I have an access database containing fruit names and its quantity. I have to connect this to vb.net. My appln also asks for personal data like Name, Address, Date, Zipcode, Email id etc. I have to validate each entry as well. Here are few things that i want to know:
1) For the date validation, it should pass certain formats like MM/DD/YYYY, DD/MM/YYYY etc..wherein i should account for leap years. I have used a logic but i dont know how i should pull out the YYYY part of the Regex() to validate the year. (Should check if its divisible by 4 and then 100 and then 400).
2) For the database connection, i have done what i knew (selected a grid view, browsed and connected the database) but it doesnot accept the fruits name to display that its available in the database. Please tell me what i should be doing for this. Also my application should not only display the fruit entered by the user with its respective quantity, it should also pass its plurals i.e should pass both apple and apples (another E.g. also berry and berries) though it is only apple in the database.

Here's my code. I am not very proficient in this topic. So detailed help would be appreciated.

Here's default.aspx.vb
CODE



Imports System.Data.OleDb

Partial Class _Default
    Inherits System.Web.UI.Page



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

        'Validating the Name field'
        If TextBox1.Text.Length = 0 Then
            Label2.Text = "Name should contain atleast one character"
        Else
            Label2.Text = ""
        End If

        'Validating the Address field'
        If TextBox2.Text.Length = 0 Then
            Label4.Text = "Address should contain atleast one character"
        Else
            Label4.Text = ""
        End If

        'Validating the Zipcode'
        Dim zipcheck As New Regex("^\d{5}$|^\d{5}[-]\d{4}$|^\d{9}$|^\d{5} \d{4}$|^\d{5} [-] \d{4}$")
        If Not zipcheck.IsMatch(TextBox3.Text) Then
            Label6.Text = "Zipcode should follow format"
        Else
            Label6.Text = ""
        End If

        'Validating Email ID'
        Dim emailcheck As New Regex("^[A-Za-z0-9]+([_.]{1}[A-Za-z0-9]+)*@[A-Za-z0-9]+([_.]{1}[A-Za-z0-9]+)*\.[A-Za-z]{2,3}$")
        If Not emailcheck.IsMatch(TextBox4.Text) Then
            Label8.Text = "Incorrect Email id format entry"
        Else
            Label8.Text = ""
        End If

        'Validating Date'
        Dim datecheck As New Regex("^\d{2} \d{2} \d{4}$|^\d{2}/\d{2}/\d{4}$|^\d{1}/\d{1}/\d{4}$|^\d{2}[-]\d{2}[-]\d{4}$|^\d{2} ([a-zA-Z]+) \d{4}$|^[a-zA-Z]{3} \d{2} \d{4}$")
        If Not datecheck.IsMatch(TextBox5.Text) Then
            Label10.Text = "Incorrect Date format entry"
        ElseIf Not IsDate(TextBox5.Text) Then
            Label10.Text = "Incorrect Date format entry..should enter as MM/DD/YYYY only!!"
        Else
            Label10.Text = ""
        End If


        ' Using System.Data.OleDb
        Dim conn = New OleDbConnection() 'to create a connection object

        '//to connect to your database
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\kashyap\Documents\Visual Studio 2005\WebSites\proj1\App_Data\fruits.mdb"

                ' open the connection
        conn.Open()
      
        Dim cmd As OleDbCommand = New OleDbCommand("fname", conn)

        ' close the connection with
        conn.Close()
      
        'Validating Fruit entry

        Dim fruitcheck As New Regex("^[a-zA-Z]*&")
      
        If Not fruitcheck.IsMatch(cmd.CommandText) Then
            Label12.Text = "Fruit not found in the database"
        Else
            Label12.Text = ""
        End If
    End Sub

End Class



User is offlineProfile CardPM
+Quote Post

prads
RE: Connecting Access Database To Vb.net And Validation
26 Feb, 2008 - 10:52 AM
Post #2

D.I.C Head
**

Joined: 22 Oct, 2007
Posts: 111


My Contributions
somebody please help.
Thanks,
prads
User is offlineProfile CardPM
+Quote Post

prads
RE: Connecting Access Database To Vb.net And Validation
26 Feb, 2008 - 10:58 AM
Post #3

D.I.C Head
**

Joined: 22 Oct, 2007
Posts: 111


My Contributions
Hello,
I could connect the database to the code. However iam having some problems with the date validation. i used "isleapyear()" function but still having certain problems. Also i need a thank you page which should be displayed after all the data is entered that contains the "Thank you for your info" note and the fruits pulled out from the database. How do i create this thankyou page? What all should be done so that this appears with the desired data after hitting the submit button.
thanks,
prads
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:29PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month