Using SQL Server 2005, vb.net
Table1
Name FromDate ToDate
Raja 12/02/2010 14/02/2010
Ravi 14/02/2010 15/02/2010
Ramu 18/02/2010 21/02/2010
...,
Insert into Table1 values('" & textbox1.text & "', '" & textbox2.text & "'. '" & textbox3.text & "'", con)
When i try to insert a value into table1 it will compare the table values if it is same, It Should throw a error msg “Name and Date Already Exist” otherwise Insert a value.
Before Inserting i want to check a textbox value with table value.
Can any one give a sample idea or code for this.
In T-SQL:
And then call this from a parametrized query in your VB.NET code.
For details about RAISERROR, see the MSDN docs: http://msdn.microsoft.com/en-us/library/ms178592.aspx. The value “10” here is the severity, the “1” is the state. You can see a list of all available severities and states in the MSDN docs.
Or wrap the whole statement into a stored proc that deals with all of this, and just call that stored proc.
UPDATE:
Create a stored proc:
and then call that from your code (I’m not fluent in VB.NET – this is C#, but should be simple enough to translate):
That nicely encapsulates everything into a single method – does that work for you??