ASP.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a ASP.NET Expert!

Join 307,023 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 2,179 people online right now. Registration is fast and FREE... Join Now!




inserting data into database

 

inserting data into database

Fusion.01

18 Jun, 2009 - 01:55 AM
Post #1

New D.I.C Head
*

Joined: 17 Jan, 2009
Posts: 37

CODE
Imports System.Data.SqlClient

Partial Class Feedbacks
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        txtName.Text = txtName.Text.Replace("'", "''")
        txtEmail.Text = txtEmail.Text.Replace("'", "''")
        TxtFeedbackDesc.Text = TxtFeedbackDesc.Text.Replace("'", "''")
        Dim FeedbackId As String = Session("FeedbackId")
        If (FeedbackId = "") Then
            FeedbackId = createFeedbackId()
            Session("FeedbackId") = FeedbackId
        End If
    End Sub
    Function createFeedbackId() As String
        Dim connectionString As String = _
        ConfigurationManager.ConnectionStrings("FeedbackConnectionString").ConnectionString
        Dim connection As SqlConnection = New SqlConnection(connectionString)
        connection.Open()
        Dim sql As String = "INSERT INTO Feedback(FeedbackID,Name,Email,FeedbackDesc) VALUES('" & txtName.Text.Trim & "','" & TxtEmail.Text.Trim & "','" & TxtFeedbackDesc.Text.Trim & "');"


        Dim command As SqlCommand = New SqlCommand(sql, connection)

        connection.Close()
    End Function
    

End Class




the when i submit this feedback,the recorde is not inserted into the databasae.help out please!

This post has been edited by Fusion.01: 18 Jun, 2009 - 02:17 AM

User is offlineProfile CardPM
+Quote Post


eclipsed4utoo

RE: Inserting Data Into Database

18 Jun, 2009 - 04:47 AM
Post #2

Not Your Ordinary Programmer
Group Icon

Joined: 21 Mar, 2008
Posts: 1,846



Thanked: 205 times
Dream Kudos: 500
Expert In: .NET

My Contributions
you have "FeedbackID" in as a field that you are going to insert a value into, but you aren't giving it a value in the "Values".
User is offlineProfile CardPM
+Quote Post

Fusion.01

RE: Inserting Data Into Database

18 Jun, 2009 - 05:33 AM
Post #3

New D.I.C Head
*

Joined: 17 Jan, 2009
Posts: 37

but in my page i only have 3 text box for name,email and feedback. so how should i design it as i think a feedbackId is essential for the function ya?
User is offlineProfile CardPM
+Quote Post

Fusion.01

RE: Inserting Data Into Database

18 Jun, 2009 - 06:04 AM
Post #4

New D.I.C Head
*

Joined: 17 Jan, 2009
Posts: 37

CODE
Function createFeedbackId() As String
        Dim connectionString As String = _
        ConfigurationManager.ConnectionStrings("FeedbackConnectionString").ConnectionString
        Dim connection As SqlConnection = New SqlConnection(connectionString)
        connection.Open()
        Dim sql As String = "INSERT INTO Feedback(Name,Email,FeedbackDesc) VALUES('" & txtName.Text.Trim & "','" & TxtEmail.Text.Trim & "','" & TxtFeedbackDesc.Text.Trim & "');"
        Dim command As SqlCommand = New SqlCommand(sql, connection)
        Dim reader As SqlDataReader = command.ExecuteReader()
        Dim FeedbackId As Integer = -1
        If (reader.Read()) Then
            FeedbackId = reader.GetValue(0)
        End If
        connection.Close()
        Return FeedbackId
    End Function
End Class


there's a error saying that my feedbackId is null.some help here please
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo

RE: Inserting Data Into Database

18 Jun, 2009 - 06:57 AM
Post #5

Not Your Ordinary Programmer
Group Icon

Joined: 21 Mar, 2008
Posts: 1,846



Thanked: 205 times
Dream Kudos: 500
Expert In: .NET

My Contributions
your feedbackID should be an auto-incrementing value. You would do this by setting that column as an identity seed in the database. Then you would remove it from your insert.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 08:11AM

Live ASP.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

ASP.NET Tutorials

Reference Sheets

ASP.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month