Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I don't know how else to form this question. I am trying to teach myself a new language in three weeks. Can you please give me some advice on how to clean my code and make it faster or more reliable? This works fine. I don't "need" any 'free' code, I need the knowledge of what I am doing wrong, and what I am doing right so I can learn. please

   Using sqlCon = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ITCSDatabase.mdf;Integrated Security=True")
        Dim resultVar As String
        sqlCon.Open()
        Dim sqlText = "SELECT appLink FROM appTable WHERE Id = @name"
        Dim cmd = New SqlCommand(sqlText, sqlCon)
        cmd.Parameters.AddWithValue("@name", x)
        resultVar = cmd.ExecuteScalar()
        cmd.ToString()
        If y = 1 Then
            System.Diagnostics.Process.Start(resultVar)
        ElseIf y = 0 Then
            System.Diagnostics.Process.Start("iexplore.exe", resultVar)
        Else
            MsgBox("When calling the appCall Function, an invalid parameter is being sent in.")
        End If
        Dim sqlText2 = "UPDATE appTable SET appClickCount = appClickCount + 1 " & _
        "WHERE Id = @x"
        Dim cmd2 = New SqlCommand(sqlText2, sqlCon)
        cmd2.Parameters.AddWithValue("@x", x)
        cmd2.ExecuteNonQuery()
End Using
share|improve this question

1 Answer

As you're beginner, your code can be considered ok.

However you may want to consider following points which help you to write reliable (maintainable) code and improve performance.

  • You want to store connectionstring to some common place like web.config. You don't have to find and change it all over the place you used it, just change at one place and it will be reflected.
  • You may want to use stored procedure instead of inline query. With stored procedure, your sql code will be more maintainable and you can go through execution plan of sql code to find out any performance bottleneck. To change sql code you don't have to modify and compile your .net code.

I hope it helps!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.