Showing posts with label builds. Show all posts
Showing posts with label builds. Show all posts

Friday, March 23, 2012

How can I bind to an SqlDataSource from Code

My code behind file builds a select statement and I would like to fill an SqlDataSource control with it. Can some show me an example of how I might do that? Maybe something like this?

Me.SqlDataSourceSearchResult.ConnectionString ="ConnectStr"Me.SqlDataSourceSearchResult.SelectCommand ="SelectStatement"

gvSearchResult.DataSource =

Me.SqlDataSourceSearchResult

gvSearchResult.DataBind()

Hello Jackxxx,

If you are going to be doing this in code-behind, I would not bother with the SqlDataSource control. I would bind the data directly to the destination control as follows: -

Dim conn As New SqlConnection("YourConnectionString")
Dim command As New SqlCommand("SELECT * FROM YourTable", conn)
Dim da As New SqlDataAdapter(command)
Dim tblData As New DataTable
da.Fill(tblData)
conn.close()

gvSearchResult.DataSource = tblData
gvSearchResult.DataBind()

Also add the following 2 lines at the top of the code behind if they are not there already: -

Imports System.Data.SqlClient
Imports System.Data

Kind regards

Scotty

|||

Scotty,

I was trying to use the sqldatasource so that I could some how use its built in sort functionality.

|||

Hello Jackxxx,

I see now. In that case, do the following after populating tblData: -

Dim dvData as new DataView(tblData)

dvData.Sort = "MyField DESC" ' you can also apply filtering on a DataView

mygrid.DataSource = dvData ' binds to the DataView, not the DataTable

mygrid.DataBind()

Kind regards

Scotty

|||

I'm really hoping to find a way to bind to the SqlDataSource so that I can take advantage of sorting and paging for multiple fields without all the extra coding.

There must be a way.

|||

Hi Jack,

Suppose your SqlDataSource returns a DataSet, you can

mygrid.DataSource = sqlDatasource.Select()
mygrid.DataBind()

However, if you need to take advantage of sorting and paging, I suggest you bind with the designer.

Monday, February 27, 2012

hotfixes - general question

Whaer can I get a list of the hotfixes/interim builds etc
post sp3(a).
TIA,
JBHave a look at :
http://support.microsoft.com/common...=&maxresults=20
Rgds,
Paul Ibison (SQL Server MVP)|||Personally, I like the guys at the SQL Security website.
Try this:
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=37
Sincerely,
Anthony Thomas
--
"JB" <anonymous@.discussions.microsoft.com> wrote in message news:95c501c4d
489$1b02c170$a401280a@.phx.gbl...
Whaer can I get a list of the hotfixes/interim builds etc
post sp3(a).
TIA,
JB

hotfixes - general question

Whaer can I get a list of the hotfixes/interim builds etc
post sp3(a).
TIA,
JB
Have a look at :
http://support.microsoft.com/common/...&maxresults=20
Rgds,
Paul Ibison (SQL Server MVP)
|||Personally, I like the guys at the SQL Security website.
Try this:
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=37
Sincerely,
Anthony Thomas

"JB" <anonymous@.discussions.microsoft.com> wrote in message news:95c501c4d489$1b02c170$a401280a@.phx.gbl...
Whaer can I get a list of the hotfixes/interim builds etc
post sp3(a).
TIA,
JB

hotfixes - general question

Whaer can I get a list of the hotfixes/interim builds etc
post sp3(a).
TIA,
JBHave a look at :
http://support.microsoft.com/common/canned.aspx?r=d&h=microsoft%20sql%20server%202000%20post-sp3%20hotfixes&ll=&sz=kbsqlserv2000presp4fix&fr=&du=&sd=gn&ln=en-us&cnd=1&vr=&cat=&vrl=&sg=&maxresults=20
Rgds,
Paul Ibison (SQL Server MVP)