Web Application help
Web Application help
Web Application help
Web Application help
Web Application help
Web Application help Web Application help Web Application help Web Application help Web Application help Web Application help Web Application help Web Application help
Web Application help Web Application help
Web Application help
Go Back  Xtreme Visual Basic Talk > > > Web Application help


Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2008, 12:29 AM
Reilly911 Reilly911 is offline
Newcomer
 
Join Date: Oct 2008
Posts: 1
Default Web Application help


Trying make a web app for school, i know very little about VB so ifu do response don't make your response really complex.

ok so,
The user enters there email into the textbox, clicks submit and i wont it to be entered into the database.

heres the code
im dashDataSource As New SqlDataSource()
dashDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("dashConnectionString1").ToStri ng()

dashDataSource.InsertCommandType = SqlDataSourceCommandType.Text
dashDataSource.InsertCommand = "INSERT INTO Email (EmailAddress) VALUES (@EmailAddress)"

dashDataSource.InsertParameters.Add("EmailAddress", emailAddressTextBox.Text)
'dashDataSource.InsertParameters.Add("DateTimeStamp", DateTime.Now())
'dashDataSource.InsertParameters.Add("IPAddress", Request.UserHostAddress)

Dim rowsAffected As Integer = 0


Try
rowsAffected = dashDataSource.Insert()
Catch ex As Exception

Server.Transfer("newsletter_problem.aspx")

Finally
dashDataSource = Nothing

End Try

If rowsAffected <> 1 Then
Server.Transfer("newsletter_problem,aspx")
Else
Server.Transfer("newsletter_confirm.aspx")

End If







End Sub


its not entering the data into the database.
Any ideas?
Reply With Quote
  #2  
Old 10-24-2008, 12:16 PM
geekzster geekzster is offline
Newcomer
 
Join Date: Aug 2007
Location: Tampa, FL. USA
Posts: 10
Default

I don't see where you are opening a connection to a database.

Try using:

SqlConnection
SqlCommand
SqlCommand.ExecuteNonQuery


Also a tip for your statement - make sure that once it is built it reads like:
Code:
INSERT INTO Email (EmailAddress) VALUES ('EmailAddress')
in other words, don't forget the single quotes around your arg.

Dont forget to Try/Catch/Finally and close your connection.

Let me know what you find out, I can help a little more, but since it is a homework assignment, I'm not going to give it away. :P
Reply With Quote
  #3  
Old 10-25-2008, 12:30 AM
Targe Targe is offline
Contributor
 
Join Date: Nov 2006
Posts: 615
Default

Like the above poster said, try using a SqlCommand object, not a SqlDataSource. Once you've instantiated the command object, giving it the query AND the connection string, you will need to Open the connection. Once the connection is opened you can then call the ExecuteNonQuery method which will run your SqlCommand object. Make SURE that you Close your connection AND dispose of the SqlCommand object before leaving the sub/function/whatever. SqlCommand objects are unmanaged variables so you have the potential of memory leaks if you do not program it as such.

Try/Catch blocks are OK but I use them sparingly personally. If you implement them you should make sure you have a Finally to dispose of the unmanaged objects. Personally, I find the Using feature works a little better. Using makes sure the object gets removed when it is finished in the Using block.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Web Application help
Web Application help
Web Application help Web Application help
Web Application help
Web Application help
Web Application help Web Application help Web Application help Web Application help Web Application help Web Application help Web Application help
Web Application help
Web Application help
 
Web Application help
Web Application help
 
-->