I am running SQL 2005 Standard Server. I am using Visual Studio 2010 for development.

Let me just say that what I have below works, I would just like to have some constructive critisism.

Is this the best way?
Is there a better way?
Are there any things I need to look out for doing it this way?

Any help would be greatly appreciated,
JTok

Dim InsertQuery As String = "INSERT USING STORED PROCEDURE"

        Using myConnection As New System.Data.SqlClient.SqlConnection("ConnectionString")

            Using myCommand As New System.Data.SqlClient.SqlCommand(InsertQuery, myConnection)

                Dim retvalue As Integer

                myConnection.Open()

                retvalue = myCommand.ExecuteNonQuery()

                Console.WriteLine(retvalue)

            End Using

        End Using

    End Sub

That looks good. Just a few things to check out.

1 - The Connection String is recommended to keep it in one place, like the web.config if you are in web development or some ini file.

2 - The ExecuteNonQuery() method is a really common use one. So if you can create a separate class and create a function to receive the string query and the connection(the last parameter only need it if you deal with different database), return an integer. this help to avoid repeating code.

3 - this is just a recommendation, something different, check "LINQ" .

Thank you very much. LINQ looks very useful indeed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.