Results 1 to 6 of 6

Thread: How to view data from sql server to asp.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up How to view data from sql server to asp.net

    Hi

    I write the below code for view the sql data in the asp.net text box.This code is running no error.But no output that is not view in the text box.Is any error?Please Reply to me.

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim connectionstring As String
    Dim connection As New SqlConnection
    Dim command As New SqlCommand

    Dim strProject As String = "Project1"


    connectionstring = "Persist Security Info=False;User ID=sa;Initial Catalog=dbmDirectCP;Data Source=IWAPPSVR\IWSQLDB"

    connection = New SqlConnection(connectionstring)

    command = connection.CreateCommand()

    connection.Open()

    If Label1.Text = "Project1" Then

    TextBox1.ReadOnly = True

    command.CommandText = "select strProjectDesc from tblProject where strProjectName='" & strProject & "'"

    command.ExecuteNonQuery()


    End If

    Thanks

  2. #2
    Member
    Join Date
    Jun 2007
    Posts
    37

    Re: How to view data from sql server to asp.net

    i'm still a n00b to but i'll try to answer your problem. just correct me if i'm wrong.

    i think u need a data reader to read the data n dataset to get the data

    for more explanation go to this site ( i know this site from other thread in this forum )
    http://samples.gotdotnet.com/quickst...soverview.aspx

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to view data from sql server to asp.net

    Your code is fine until

    Code:
    command.ExecuteNonQuery()
    Because that specifies nothing returned (just the number of rows affected).

    You want to use

    Code:
    string strResult = command.ExecuteScalar()

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: How to view data from sql server to asp.net

    ya fine menthak,

    I got that.

    Thanks for ur time

  5. #5
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: How to view data from sql server to asp.net

    I'm not really convinced that the SELECT command would work, because it's missing a few things... look at this command straight from one of my projects. Shouldn't be hard to figure out what yours is missing.

    Code:
    "SELECT [ID], [strName] FROM [tblProductLine] ORDER BY [strName]"

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to view data from sql server to asp.net

    Seems fine to me.

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