Topic:When submitting ASP.NET form, SQL Server fields only show the first letter Remainpoint:0
   
PostTime:12/16/2008 8:02:10 PM FloorTop
Lv is 1
Avatar
Level:
1
Professional point:
91
Experience:
26
Thread:
283
Post:
971
Total online time:
26M
Joined date:
4/28/2007 10:46:00 PM
Last Visit:
12/17/2008 12:14:45 AM
Status:
Offline
Hi, I'm new around here and am stumped. I have created a form where I submit the information into a SQL Server 2000 table. When I submit the information through the form, only the first character of each field populates inside of the SQL table. This happens for every field except for two, zip and comments. The zip field is numeric and the comments field is text. All the other fields are varchar fields; and these are the fields with the problems. I have attempted to change the data type to text, but that did not work either. I am doing this through a stored procedure I created.

Here is the asp code:


Public Class WebForm1

Inherits System.Web.UI.Page

Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox

Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox

Protected WithEvents txtAddress1 As System.Web.UI.WebControls.TextBox

Protected WithEvents txtAddress2 As System.Web.UI.WebControls.TextBox

Protected WithEvents txtCity As System.Web.UI.WebControls.TextBox

Protected WithEvents txtZip As System.Web.UI.WebControls.TextBox

Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox

Protected WithEvents txtPhone As System.Web.UI.WebControls.TextBox

Protected WithEvents txtComments As System.Web.UI.WebControls.TextBox

Protected WithEvents ddlState As System.Web.UI.WebControls.DropDownList

Protected WithEvents ddlGift1 As System.Web.UI.WebControls.DropDownList

Protected WithEvents ddlGift2 As System.Web.UI.WebControls.DropDownList

Protected WithEvents ddlGift3 As System.Web.UI.WebControls.DropDownList

Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection

Protected WithEvents SqlCommand1 As System.Data.SqlClient.SqlCommand

Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()

Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand()

'

'SqlConnection1

'

Me.SqlConnection1.ConnectionString = "data source=NDAVENPORT2;initial catalog=Bluestreak;integrated security=SSPI;persi" & _

"st security info=False;workstation id=NDAVENPORT2;packet size=4096"

'

'SqlCommand1

'

Me.SqlCommand1.CommandText = "dbo.[InsertFreeOrders]"

Me.SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure

Me.SqlCommand1.Connection = Me.SqlConnection1

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@firstname", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@lastname", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@address1", System.Data.SqlDbType.VarChar, 100))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@address2", System.Data.SqlDbType.VarChar, 100))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@city", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@state", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@zip", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@email", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@phone", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@item1", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@item2", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@item3", System.Data.SqlDbType.VarChar, 50))

Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@comments", System.Data.SqlDbType.VarChar, 2147483647))

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

End Sub

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

If IsValid Then

SqlCommand1.Parameters("@firstname").Value = txtFirstName.Text

SqlCommand1.Parameters("@lastname").Value = txtLastName.Text

SqlCommand1.Parameters("@address1").Value = txtAddress1.Text

SqlCommand1.Parameters("@address2").Value = txtAddress2.Text

SqlCommand1.Parameters("@city").Value = txtCity.Text

SqlCommand1.Parameters("@state").Value = ddlState.SelectedItem.Text

SqlCommand1.Parameters("@zip").Value = txtZip.Text

SqlCommand1.Parameters("@email").Value = txtEmail.Text

SqlCommand1.Parameters("@phone").Value = txtPhone.Text

SqlCommand1.Parameters("@item1").Value = ddlGift1.SelectedItem.Text

SqlCommand1.Parameters("@item2").Value = ddlGift2.SelectedItem.Text

SqlCommand1.Parameters("@item3").Value = ddlGift3.SelectedItem.Text

SqlCommand1.Parameters("@comments").Value = txtComments.Text

SqlConnection1.Open()

SqlCommand1.ExecuteNonQuery()

SqlConnection1.Close()

Response.Redirect("Success.aspx")

End If

End Sub

End Class


My stored procedure looks like this:

CREATE PROCEDURE dbo.InsertFreeOrders
(
@firstname varchar( 50 ),
@lastname varchar( 50 ),
@address1 varchar( 100 ),
@address2 varchar( 100 ),
@city varchar( 50 ),
@state varchar( 50 ),
@zip numeric,
@email varchar( 50 ),
@phone varchar( 50 ),
@item1 varchar( 50 ),
@item2 varchar( 50 ),
@item3 varchar( 50 ),
@comments text
)
AS
Insert FreeOrders
(
o_first_name,
o_last_name,
o_address_1,
o_address_2,
o_city,
o_state,
o_zip,
o_email,
o_phone,
o_item_1,
o_item_2,
o_item_3,
o_comments
) Values (
@firstname,
@lastname,
@address1,
@address2,
@city,
@state,
@zip,
@email,
@phone,
@item1,
@item2,
@item3,
@comments
)
GO

So it is working, just not completely and I am stumped here. Any help would be great! Thanks.
 
     
   
Gender PostTime:12/17/2008 12:05:10 AM Point:0 | Floor# 1
Lv is 1
portrait
Level:
1
Professional point:
98
Experience:
2
Thread:
272
Post:
982
Total online time:
2M
Joined date:
4/28/2007 11:38:00 PM
Last Visit:
12/17/2008 12:23:56 AM
Status:
Offline
Do a response.write or write the fields in question to the page before submitting them to the database. What do the results look like?

Also, try using the code tags next time. It'll make it easy for everyone else to read your code.
 
     
1

Sorry, you are not login, click here to login

 

About us | Advertise | Contact us | Partner | Bug Report|Suggesting box|Donation
Home | Forum | Affiliate program| Remote help | Setting | Search | Document | Help | Download|Message

 

Start new topicAdvanced search
Your location: Database -> Sql server