Can we use view Instead of Query

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 11
Reputation: chinni1 is an unknown quantity at this point 
Solved Threads: 0
chinni1 chinni1 is offline Offline
Newbie Poster

Can we use view Instead of Query

 
0
  #1
Dec 30th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: Can we use view Instead of Query

 
0
  #2
Dec 30th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 11
Reputation: chinni1 is an unknown quantity at this point 
Solved Threads: 0
chinni1 chinni1 is offline Offline
Newbie Poster

Re: Can we use view Instead of Query

 
0
  #3
Dec 30th, 2008
Originally Posted by Aneesh_Argent View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC