I'm still new here and even in Visual Studio so I don't fully know all the function in Visual Studio. I'm trying to make the system to check the database first for any existing staID
, staName
, depID
, and telNo
so that the system will skip the process if the data already exist.
But if there aren't any, the system will record the user input to the database.
Here's my code:
Imports System.Data.SqlClient
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS; AttachDbFilename= C:\Users\ammaramli\Documents\Visual Studio 2010\WebSites\Project\App_Data\Database.mdf; Integrated Security=True;User Instance=True")
Dim strinsert As String
Dim cmd As SqlCommand
strinsert = "INSERT INTO Staff (staID, staName, depID, telNo) values (@staID, @staName, @depID, @telNo)"
cmd = New SqlCommand(strinsert, con)
con.Open()
cmd.Parameters.AddWithValue("@staID", staID.Text)
cmd.Parameters.AddWithValue("@staName", staName.Text)
cmd.Parameters.AddWithValue("@depID", depID.Text)
cmd.Parameters.AddWithValue("@telNo", telNo.Text)
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
con.Close()
End Sub
End Class
So my question will be, how can I make it like that? It's been 2 days I'm stuck here.