Jay1b Posted March 10, 2006 Posted March 10, 2006 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() Quote
Administrators PlausiblyDamp Posted March 10, 2006 Administrators Posted March 10, 2006 You could simplify your code using one of the overloaded methods cmCreateUser.Parameters.Add("@Username", SqlDbType.Char, ).Value = txtUsername.Text 'repeat for other parameters Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.