|
-
Jun 26th, 2007, 12:10 AM
#1
Thread Starter
Addicted Member
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
-
Jun 26th, 2007, 02:33 AM
#2
Member
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
-
Jun 26th, 2007, 06:10 AM
#3
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()
-
Jun 26th, 2007, 06:17 AM
#4
Thread Starter
Addicted Member
Re: How to view data from sql server to asp.net
ya fine menthak,
I got that.
Thanks for ur time
-
Jun 26th, 2007, 08:17 AM
#5
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]"
-
Jun 27th, 2007, 07:39 AM
#6
Re: How to view data from sql server to asp.net
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|