mrsdewinter2
05-05-2008, 07:17 PM
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
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
<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
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
<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