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,161 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 1,532 people online right now. Registration is fast and FREE... Join Now!




inserting into database

 

inserting into database

tony_inaty

15 Jun, 2009 - 06:51 PM
Post #1

New D.I.C Head
*

Joined: 15 Jun, 2009
Posts: 7

CODE
Imports System.Data.SqlClient
Partial Class Register
    Inherits System.Web.UI.Page




    Protected Sub Submit1_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit1.Click
        txtName.Text = txtName.Text.Replace("'", "''")
        txtFamily.Text = txtFamily.Text.Replace("'", "''")
        txtUser.Text = txtUser.Text.Replace("'", "''")
        txtPass.Text = txtPass.Text.Replace("'", "''")
        txtEmail.Text = txtEmail.Text.Replace("'", "''")
        txtPhone.Text = txtPhone.Text.Replace("'", "''")

        Dim NonQuery As String

        Dim sqlCon As New SqlConnection(ConfigurationManager.ConnectionStrings("dbConnectionString").ConnectionString)

        NonQuery = "Insert into users(username,password,name,family,emailadress,phone number) values ('" _
        & txtUser.Text.Trim & "','" & txtPass.Text.Trim & "','" & txtName.Text.Trim & "','" _
        & txtFamily.Text.Trim & "','" & txtEmail.Text.Trim & "','" & txtPhone.Text.Trim & "');"

        Dim sqlCmd As New SqlCommand(NonQuery, sqlCon)
        sqlCon.Open()
        sqlCmd.ExecuteNonQuery()
        sqlCon.Close()

        txtName.Text = ""
        txtFamily.Text = ""
        txtUser.Text = ""
        txtPass.Text = ""
        txtEmail.Text = ""
        txtPhone.Text = ""

    End Sub

End Class


i am having an error : Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'number'.

User is offlineProfile CardPM
+Quote Post


Jayman

RE: Inserting Into Database

15 Jun, 2009 - 06:55 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,570



Thanked: 237 times
Dream Kudos: 500
Expert In: Everything

My Contributions
You cannot have a space in a column name. Should it be "phonenumber"?

CODE

"Insert into users(username,password,name,family,emailadress,phonenumber) values ('" _

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 06:05PM

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