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
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
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()
Re: How to view data from sql server to asp.net
ya fine menthak,
I got that.
Thanks for ur time
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]"
Re: How to view data from sql server to asp.net