How to check a SQL database table to see if a record exists

Posted by Anthony on Stack Overflow See other posts from Stack Overflow or by Anthony
Published on 2010-05-10T15:50:58Z Indexed on 2010/05/10 15:54 UTC
Read the original article Hit count: 396

Filed under:
|

I have a SQL database that creates a record for every document uploaded by the user to the server. I want to check this table before a user uploads a document to ensure they don't upload a file with name that already exists.

I know how to make the connection and make the SqlCommand to query the table for an existing record. But I don't know how to check the record count from the sqlCommand I made.

Does that make sense?

Using myConnectionCheck As New SqlConnection(myConnectionStringCheck)
                Dim myCommandCheck As New SqlCommand()
                myCommandCheck.Connection = myConnectionCheck
                myCommandCheck.CommandText = "SELECT * FROM Req_Docs WHERE Doc_Name =" & DocName
                myConnectionCheck.Open()
                myCommandCheck.ExecuteNonQuery()

            End Using

Thanks in advance,

Anthony

© Stack Overflow or respective owner

Related posts about aspx

Related posts about vb.net