Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    letting users who visit my website add records to sql server database

    in visual studio web developer express edition 2008 i added a new item this was a sql server database which i called test2. I added a table called comments, and the fields name, email, comments, IPAddress, and Date and in my comments.aspx page i added a name textbox, a texbox for email, a textbox for comments and the submit button i double clicked on the submit button and added the following code

    Code:
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim mydS As New SqlDataSource
            mydS.ConnectionString = ConfigurationManager.ConnectionStrings("testConnectionString1").ToString
    
            mydS.InsertCommandType = SqlDataSourceCommandType.Text
    
            mydS.InsertCommand = "INSERT INTO comments(Name,Email,Comments,IPAddress,Date) VALUES (@Name,@Email,@Comments,@IPAddress,@Date)"
    
            mydS.InsertParameters.Add("Name", TextBox1.Text)
            mydS.InsertParameters.Add("Email", TextBox2.Text)
            mydS.InsertParameters.Add("Comments", TextBox3.Text)
            mydS.InsertParameters.Add("Date", Date.Now)
            mydS.InsertParameters.Add("IPAddress", Request.Params("REMOTE_ADDR"))
    
            Dim rowsaffected As Int16 = 0
            Try
                rowsaffected = mydS.Insert
            Catch ex As Exception
                Server.Transfer("errors.aspx")
            Finally
                mydS = Nothing
            End Try
            If rowsaffected <> 1 Then
                Server.Transfer("errors.aspx")
            Else
                Server.Transfer("confirm.aspx")
            End If
        End Sub
    
        Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    
        End Sub
    but when i run it it gives me a problem with this line mydS.ConnectionString = ConfigurationManager.ConnectionStrings("testConnectionString2).ToString and says something abt unidentified object and I want to know how do i set the connection string or alternatively where?????? and my table does not update with the corresponding values i enter on the webpage. i also changed the authentication mode to forms instead of windows as i was advised but i'm still having a problem i tried adding the

    Code:
    <appSettings> 
    </appSettings>
    <connectionStrings> 
    <add name="testConnectionString2" connectionString="Server=server1;Database=test2;User ID=USERID;Password=PASSWORD;Trusted_Connection=False" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    but its still not working
    Last edited by Brandoe85; 05-06-2008 at 06:27 AM. Reason: added code tags


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •