Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 10th, 2006, 10:28 AM
Authorized User
 
Join Date: Mar 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO.Net...Help PLZ!!!!

I am trying to learn how to use ADO.Net from a book. As I am just new to programming this is turning out to be quite an event!
I have managed to populate an msAccess database with the relevant user input information however what I need to do now is search the database's "Date" column to see if there is already a date matching the users "chosen date" in the database...Gee that's long winded!
When the user inputs a chosen date for an event, which is not already chosen and stored in the db, the db accepts all other input data. However if the chosen event date is already in the db this message occurs:

An unhandled exception of type 'System.Data.ConstraintException' occurred in system.data.dll

Additional information: Column 'Date' is constrained to be unique. Value '23/04/2002 00:00:00' is already present.


Is there any way of turning this into a messagebox.show to inform the user that the date is already taken?
I really hope someone out there can help me...I'm starting to get desperate!
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 
Old March 11th, 2006, 02:54 AM
Registered User
 
Join Date: Nov 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi sconineuk
I am also new to VB.Net. Hope following Code will solve your problem.

Dim queryString As String = "Select * from [table] where Date="& datatimePicker.value & "
Dim command As New OledbCommand(queryString, connection)
Dim reader As SqlDataReader = command.ExecuteReader()

' Check Date
if reader.Read()
    messagebox.show "Date Already there. Select Other Date"
End While
        ' Call Close when done reading.
reader.Close()

Here connection is your Existing connection Name.

 
Old March 13th, 2006, 03:37 AM
Friend of Wrox
 
Join Date: May 2003
Posts: 229
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
you can use try catch block
or if you want to use MessageBox
you can easily use messagebox.show() in vb.net

Charul Shukla
 
Old March 16th, 2006, 05:15 AM
Authorized User
 
Join Date: Mar 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you two for your reply but I still cant get it to work!
I feel so unintelligent!
Can you explain to me as simply as you can how a Try/Catch works
xxx

 
Old March 16th, 2006, 05:35 AM
Authorized User
 
Join Date: Mar 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the error message that comes from running this and choosing an already saved date:

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe

Additional information: Object reference not set to an instance of an object.

What can I do now?
xxx






Similar Threads
Thread Thread Starter Forum Replies Last Post
ado and oracle procedure problem plz help zrtv Pro VB Databases 9 February 28th, 2008 01:00 PM
Difference between ADO and ADO.NET rakeshclose2u ADO.NET 2 April 23rd, 2007 03:57 AM
ADO AND ADO.NET royalsurej ADO.NET 1 November 8th, 2004 08:28 AM
I'm a bignner to ASP.NET, plz help me salman .NET Web Services 1 January 7th, 2004 05:24 PM
MSDE and SQL CE (using VB.NET and ADO.NET) LEGS ADO.NET 0 July 12th, 2003 11:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.