Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 638399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:43:42+00:00 2026-05-13T20:43:42+00:00

Using SQL Server 2005, vb.net Table1 Name FromDate ToDate Raja 12/02/2010 14/02/2010 Ravi 14/02/2010

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:43:42+00:00Added an answer on May 13, 2026 at 8:43 pm

    In T-SQL:

    IF EXISTS(SELECT * FROM dbo.Table1 WHERE Name = @Name AND FromDate = @FromDate AND ToDate = @ToDate)
       RAISERROR (N'Values already exist', 10, 1)
    ELSE
       INSERT INTO dbo.Table1(Name, FromDate, ToDate)
       VALUES(@Name, @FromDate, @ToDate)
    

    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:

    CREATE PROCEDURE dbo.InsertData(@Name VARCHAR(50), @FromDate DATETIME, @ToDate DAETIME)
    AS BEGIN
       BEGIN TRANSACTION
    
       IF EXISTS(SELECT * FROM dbo.Table1 WHERE Name = @Name AND FromDate = @FromDate AND ToDate = @ToDate)
          ROLLBACK TRANSACTION
          RAISERROR (N'Values already exist', 10, 1)
       ELSE
          INSERT INTO dbo.Table1(Name, FromDate, ToDate)
          VALUES(@Name, @FromDate, @ToDate)
    
          COMMIT TRANSACTION
    END
    

    and then call that from your code (I’m not fluent in VB.NET – this is C#, but should be simple enough to translate):

    using(SqlConnection _con = new SqlConnection('your connection string here'))
    {
        using(SqlCommand _cmd = new SqlCommand("InsertData", _con)
        {
            _cmd.CommandType = CommandType.StoredProcedure;
    
            // add parameters as necessary
            _cmd.Parameters.AddWithValue("@Name", "Your Name");
            _cmd.Parameters.AddWithValue("@FromDate", "20100101");
            _cmd.Parameters.AddWithValue("@ToDate", "20100331");
    
            try
            {
                // open connection, execute stored proc, close connection
                _con.Open();
                _cmd.ExecuteNonQuery();
                _con.Close();
            } 
            catch(SqlException sqlexc)
            {
                // handle SQL exception
            }
        }
    }
    

    That nicely encapsulates everything into a single method – does that work for you??

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2005 and VB.Net Table1 ID Name Dept 001 Raja IT 002
Using SQL Server 2005 and Management Studio how do I insert a picture into
I am using Sql Server 2005 and Vb Studios 2010 on a .net Framework
I need to write a web application using SQL Server 2005, asp.net, and ado.net.
Using VB.NET and SQL Server 2005 In my software I am using login page
I'm using VB.NET and Microsoft SQL Server 2005 to create an application. I was
I am using .NET 2.0 and SQL Server 2005. For historical reasons, the app
I am using .Net 2.0 + SQL Server 2005 Enterprise + VSTS 2008 +
I am using .Net 2.0 + SQL Server 2005 Enterprise + VSTS 2008 +
I maintain a legacy ASP.Net Web application (using .Net 2.0 + SQL Server 2005

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.