Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

The below calls a stored procedure passing the contents of a number of textboxes as parameters, these are then inserted into a database. However it seems like masses of code for what seems quite simple. It does work perfectly, but i just feel there must be a better way of doing things.

 

I've looked at using the SQLDataSource control, but i cant seem to get that working without something like a gridview - which doesnt fit into the way the screen is laid out.

 

Is there a better way for me to do this? If so, could you please give me a few pointers on what these are?

 

Thanks.

 

 

        'Enter information into user_t table

               Dim conn As New SqlConnection("Data Source=RA\SQLExpress;Initial Catalog=CReq;User ID=ASP;Password=password")
               Dim cmCreateUser As New SqlCommand("dbo.CreateUser", conn)

               cmCreateUser.CommandType = Data.CommandType.StoredProcedure
               conn.Open()

               Dim pmUsername As New SqlParameter
               pmUsername.ParameterName = "Username"
               pmUsername.Value = txtUsername.Text
               cmCreateUser.Parameters.Add(pmUsername)

               Dim pmFirstname As New SqlParameter
               pmFirstname.ParameterName = "Firstname"
               pmFirstname.Value = txtFirstName.Text
               cmCreateUser.Parameters.Add(pmFirstname)

               Dim pmSurname As New SqlParameter
               pmSurname.ParameterName = "Surname"
               pmSurname.Value = txtSurname.Text
               cmCreateUser.Parameters.Add(pmSurname)

               Dim pmALimit As New SqlParameter
               pmALimit.ParameterName = "AuthorisationLimit"
               pmALimit.Value = txtAuthorisationLimit.Text
               cmCreateUser.Parameters.Add(pmALimit)

               Dim pmSiteID As New SqlParameter
               pmSiteID.ParameterName = "SiteID"
               pmSiteID.Value = ddownSite.SelectedValue
               cmCreateUser.Parameters.Add(pmSiteID)

               cmCreateUser.ExecuteNonQuery().ToString

               conn.Close()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...