Results 1 to 6 of 6

Thread: RESOLVED!! Assigning dataset values to a text box

  1. #1

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381

    Question RESOLVED!! Assigning dataset values to a text box

    The script below gives me back a record (i.e. FNAME, LNAME, STUDENTID) that I will bind to a datagrid. After binding, I get value of each cell in the webform datagrid and place it on a webform textbox. Is there a better way to do this so that I skip the datagrid binding and assign the values to a text box directly? Do I have other option other than using a dataReader just like a recordset in VB6?

    Thanks

    Code:
                Dim connectionString As String = "server='SQLSERVER1'; user id='RAUser1'; password='letmein'; database='RA'"
                Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
    
                Dim queryString As String = "SELECT [RAUser].* FROM [RAUser] WHERE (([RAUser].[LoginName] = @LoginName) AND ([" & _
        "RAUser].[LoginPass] = @LoginPass))"
                Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
                dbCommand.CommandText = queryString
                dbCommand.Connection = dbConnection
    
                Dim dbParam_loginName As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
                dbParam_loginName.ParameterName = "@LoginName"
                dbParam_loginName.Value = loginName
                dbParam_loginName.DbType = System.Data.DbType.String
                dbCommand.Parameters.Add(dbParam_loginName)
                Dim dbParam_loginPass As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
                dbParam_loginPass.ParameterName = "@LoginPass"
                dbParam_loginPass.Value = loginPass
                dbParam_loginPass.DbType = System.Data.DbType.String
                dbCommand.Parameters.Add(dbParam_loginPass)
    
                dbConnection.Open()
                Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    	    Return dataReader
    Last edited by ARPRINCE; Feb 16th, 2004 at 12:31 PM.

  2. #2

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    I tried using the SqlConnection data provider class but I may be missing something. Here's what I did:

    (1) Created a new PROJECT using VS.
    (2) Created a new web form (WebForm1.aspx).
    (3) Under the WebForm1.aspx.vb page_load, I typed :

    Code:
    Dim con As New sqlconnection("my connectionstring")

    The sqlconnection is underlined. Am I missing a reference?

  3. #3

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    Ok. I used this one instead. I needed to add SqlClient so that I will get a correct syntax (with out underlines).

    VB Code:
    1. Dim dataCON As New SqlClient.SqlConnection("server='XXXXXX'; user id='XXXXXX'; password='XXXXXX'; database='XXXXXX'")
    2.         dataCON.Open()
    3.         Dim dataCMD As New SqlClient.SqlCommand("Select * from rauser", dataCON)
    4.         Dim dataREADER As SqlClient.SqlDataReader = dataCMD.ExecuteReader()
    I got the value of each cell of the dataset by using:

    VB Code:
    1. dataREADER.GetValue(FieldIndex)
    Anyone knows how I can get rid of the "SqlClient" so that I don't need to type it in on every program line?

    Thanks

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    You should have an "Imports System.Data" statement at the top of your pages, change it to "Imports System.Data.SqlClient" and you won't have to use SqlClient in your code.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    Originally posted by Memnoch1207
    You should have an "Imports System.Data" statement at the top of your pages, change it to "Imports System.Data.SqlClient" and you won't have to use SqlClient in your code.
    Would this be on the MyPage.aspx.vb ? At the top of this page I only see (using Visual Studio):

    VB Code:
    1. Public Class Login
    2.     Inherits System.Web.UI.Page

    My HTML code shows only this one:
    Code:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Login.aspx.vb" Inherits="RA.Login"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>Login</title>
    		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    		<meta content="JavaScript" name="vs_defaultClientScript">
    		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    	</HEAD>
    .......

    I see this when I check my references:
    Attached Images Attached Images  

  6. #6

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381

    Thumbs up

    VB Code:
    1. Imports System.Data.SqlClient
    2.  
    3. Public Class Login
    4.     Inherits System.Web.UI.Page
    I place the syntax under the general declaration portion of my vb code.

    Thanks.
    Last edited by ARPRINCE; Feb 16th, 2004 at 06:21 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width