By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,231 Members | 1,420 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,231 IT Pros & Developers. It's quick & easy.

Extra space in database when data is entered

P: n/a
I have a problem with ASP.NET and entering data into a MS SQL database.
I have the following

code and what happens is the data gets into the database, but with one
extra space at the end of

the entry. Is this preventable with something other than a trim in my
stored procedure? I know this is not necessarily in ASP.NET because I
returned the value with quotes around it and it shows up right, but
when I look in the database, it is wrong. I think it is with the SQL

ASP.NET code

<%@ Page Language="VB"%>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">

Function gstrConn As String
gstrConn = "Provider = SQLOLEDB;" & _
"Initial Catalog = main;" & _
"Data Source =;" & _
"User Id = someuser;" & _
"PASSWORD = password"
End Function

Function SignUpUser(strUserName As String, strPassword As String) As
SignUpUser = False

Dim booResult As Boolean = False
Dim intUserId As Integer = 0

Dim objConn As New OleDbConnection(gstrConn)
Dim objCmd As OleDbCommand
Dim objParam As OleDbParameter
Dim objReader As OleDbDataReader
Dim ds As DataSet = New DataSet()

objCmd = New OleDbCommand("signup_user", objConn)
objCmd.CommandType = CommandType.StoredProcedure
objParam = objCmd.Parameters.Add("@user_name", OleDbType.Char)
objParam.Direction = ParameterDirection.Input
objParam.Value = strUserName
objParam = objCmd.Parameters.Add("@password", OleDbType.Char)
objParam.Direction = ParameterDirection.Input
objParam.Value = strPassword

objReader = objCmd.ExecuteReader
Catch Ex As OleDbException
SignUpUser = False
Exit Function
End Try

While objReader.Read()
intUserId = objReader.GetInt32(0)
End While


If intUserId > 0 Then
booResult = True
booResult = False
End If

SignUpUser = booResult
End Function

Sub Page_Load(Sender As Object, E As EventArgs)

End Sub

Sub btnSignUp_Click(Sender As Object, E As EventArgs)
lbltesttext.text = chr(34) & tbtesttext.text & chr(34)
SignUpUser(tbtesttext.text, tbtesttext.text)
End Sub

Sub btnReset_click(Sender As Object, E As EventArgs)
lbltesttext.text = ""
End Sub


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META http-equiv=Content-Type content="text/html; charset=utf-8">

<FORM runat="server">

<asp:label id="lbltesttext" runat="server"/>
<asp:textbox id="tbtesttext" runat="server"/>
<asp:button id="btntesttext" text="Test" onclick="btnSignUp_Click"
<asp:button id="btnReset" text="Reset" onclick="btnReset_click"



MS SQL Stored Procedure


@user_name VARCHAR(32),
@password VARCHAR(32)


INSERT INTO forum_users
(forum_user_name, forum_user_password)
VALUES(@user_name, @password)

Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies

P: n/a
What are the SQL data types in this table? Are they char (fixed
length) or varchar (variable length). If they are char, then your
entries will likely be padded with spaces unless they are of the exact
length as the column length.

Bill E.
Hollywood, FL

Nov 19 '05 #2

P: n/a
It is varchar.

Nov 19 '05 #3

P: n/a
You might want to try using OldDbType.VarChar for those parameters.


On 24 May 2005 15:00:45 -0700, vo******** wrote:
It is varchar.

Nov 19 '05 #4

P: n/a
In ASP.NET or in MS SQL (the Stored Procedure)?

Nov 19 '05 #5

P: n/a
In ASP.NET. That way the parameter types in your command object will
match the sproc parameter types.


On 4 Jun 2005 18:54:41 -0700, vo******** wrote:
In ASP.NET or in MS SQL (the Stored Procedure)?

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.