943,632 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 735
  • ASP.NET RSS
Dec 30th, 2008
0

Can we use view Instead of Query

Expand Post »
This is my code.Here Instead of query string can i use view.
plz reply me.


Protected Sub btnchk_name_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnchk_name.Click
Dim str As String = "select ID from table1 where ID = '" & txtid.Text & "'"
Dim con As String = ConfigurationManager.AppSettings("preeconn")
Dim com As New SqlCommand(str, New SqlConnection(con))
com.Connection.Open()
Dim da As New SqlDataAdapter(str, con)
Dim dr As SqlDataReader
dr = com.ExecuteReader 'where sqldatareader ain't run without using
If Not dr.Read() Then
datagrid.datasource=com.executereader()
datagrid.databind()
End If
End Sub
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chinni1 is offline Offline
11 posts
since Dec 2008
Dec 30th, 2008
0

Re: Can we use view Instead of Query

Can you pls explain your objective first. I cant get it form you code. I have made some comments in your code. Can u pls explain those things

Protected Sub btnchk_name_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnchk_name.Click
Dim str As String = "select ID from table1 where ID = '" & txtid.Text & "'"
Dim con As String = ConfigurationManager.AppSettings("preeconn")
Dim com As New SqlCommand(str, New SqlConnection(con))
com.Connection.Open()

Dim da As New SqlDataAdapter(str, con)
' I cant see you using this object anywhere
Dim dr As SqlDataReader
dr = com.ExecuteReader 'where sqldatareader ain't run without using

' Are you sure this is the condition you really meant to give
If Not dr.Read() Then

datagrid.datasource=com.executereader()
' When you already have the result of your query in the sqldatareader object, why are u executing the same query the again, you could have used the same old object
datagrid.databind()

End If
End Sub
Reputation Points: 16
Solved Threads: 18
Junior Poster
Aneesh_Argent is offline Offline
104 posts
since Dec 2008
Dec 30th, 2008
0

Re: Can we use view Instead of Query

Can you pls explain your objective first. I cant get it form you code. I have made some comments in your code. Can u pls explain those things

Protected Sub btnchk_name_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnchk_name.Click
Dim str As String = "select ID from table1 where ID = '" & txtid.Text & "'"
Dim con As String = ConfigurationManager.AppSettings("preeconn")
Dim com As New SqlCommand(str, New SqlConnection(con))
com.Connection.Open()

Dim da As New SqlDataAdapter(str, con)
' I cant see you using this object anywhere
Dim dr As SqlDataReader
dr = com.ExecuteReader 'where sqldatareader ain't run without using

' Are you sure this is the condition you really meant to give
If Not dr.Read() Then

datagrid.datasource=com.executereader()
' When you already have the result of your query in the sqldatareader object, why are u executing the same query the again, you could have used the same old object
datagrid.databind()

End If
End Sub


Actually my question is can we use views instead of query in our code.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chinni1 is offline Offline
11 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Session Variable - Question
Next Thread in ASP.NET Forum Timeline: file upload





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC