Wrox Programmer Forums
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 27th, 2007, 01:13 AM
Friend of Wrox
Join Date: Aug 2006
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post
Default date reader problem

Hello to all
My problem is :
i am using data reader to read values from datatable which have two fields Username and Password. when i match my textbox values to table values, datareader takes datatable value as "text " i.e including all the length of that field which cause always non matching. i want that it should not take spaces and whole length of field just the values.
i am writing the code i am using and marking the problem.


Dim sqlSelect As String

        Dim strUserName, strPassword As String
        strUserName = txtUserName.Text
        strPassword = txtPassword.Text
        sqlSelect = "Select * from Login"
        Dim cmd As SqlCommand
        Dim oDataReader As SqlDataReader
        cmd = New SqlCommand(sqlSelect, cn)
        cmd.CommandType = CommandType.Text
        cmd.Connection = cn
        oDataReader = cmd.ExecuteReader()
        While oDataReader.Read()
            Dim dbUserName As String
            Dim dbPassword As String
            dbUserName = oDataReader("UserName").ToString()
//This dbusername getting the Value "test ". but it should get "test" only.
            dbPassword = oDataReader("Password")

                 If (dbUserName = strUserName) Then
                If(dbPassword = strPassword) Then

            End If
            End If
        End While


Old April 27th, 2007, 07:55 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi

Hi there...

a couple of things:

This way of read user is no a good one.. what if you have 1000 users??? you will read all the table to see if there are a matching user?? better try to get the user directly from the database (do a Sql passing the user and password.. and please use parameters to avoid an sql injection)...

The problem with the fields filled with spaces is probably a database problem, witch database are you using and what is the field definition?

Replace response.redirect with server.transfer... redirect cause an unnecessary round trip to the client.



================================================== =========
Read this if you want to know how to get a correct reply for your question:
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
================================================== =========
Old April 30th, 2007, 12:04 AM
Friend of Wrox
Join Date: Aug 2006
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post

thanks for your valuable suggestions
i will implement that.
rather i solve my problem my appliying trim function at the end i.e



Similar Threads
Thread Thread Starter Forum Replies Last Post
Log reader franklink C++ Programming 1 June 26th, 2009 08:40 AM
Excel File Reader Problem umair.hasan ASP.NET 1.0 and 1.1 Professional 0 August 17th, 2007 11:12 AM
Need Help BarCode Reader arshhb General .NET 0 August 12th, 2007 02:11 AM
sql data reader problem MunishBhatia ASP.NET 2.0 Professional 0 December 9th, 2006 05:51 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.