2 Replies - 5876 Views - Last Post: 26 February 2008 - 11:58 AM Rate Topic: -----

#1 prads  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 22-October 07

connecting access database to vb.net and validation

Post icon  Posted 24 February 2008 - 05:25 PM

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


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



Is This A Good Question/Topic? 0
  • +

Replies To: connecting access database to vb.net and validation

#2 prads  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 22-October 07

Re: connecting access database to vb.net and validation

Posted 26 February 2008 - 11:52 AM

somebody please help.
Thanks,
prads
Was This Post Helpful? 0
  • +
  • -

#3 prads  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 113
  • Joined: 22-October 07

Re: connecting access database to vb.net and validation

Posted 26 February 2008 - 11:58 AM

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1