DataSource Controls :: Pointing To The SqlSelecting Event In The Code Behind SqlConnection?
Jan 26, 2010
I know you can point to a OnSelecting event on the aspx page datasource. But I've created my SqlDataSource in the code behind. Is there any way to point to a selecting event in the code behind (I need this to provide the parameters)? Or should I just include all my logic in the Page_Load event (where I keep my SqlConnection)Here's what I have so far:
i have 5 methods in classA. each and every methods i have open the sqlconnection and close it, instead of that is there anyway to create a sqlconnection at one time if its opened then no need to create a new connection, if its closed then we have to connect.
I have a whole bunch of data access methods where in each one I am doing this
[Code]....
and them moving on with my SqlCommand and SqlDataReader and so on.Is this creating to many instances of an SQLConnection?I was thinking doing this instead. Creating a SqlConnection Manager which would look like this
[Code]....
and then in my database access methods
[Code]....
Is this a good or bad idea and why?Also would this even be neccesary?
I'm trying to determine whether it is better to declare the connection outside with it's own using statement or to create it inside the sqlcommand itself. This is in regards to a single command interaction with the database (no loops).
It doesn't happen often but from time to time I'll get an exception report emailed to me pointing to this bit of code. I'm wondering if you see anything wrong with it:
Csharp Code: namespace DomainModel.Concrete { public class ConfigRepository : IConfigRepository static mvCmsContext context { get; set; } public ConfigRepository() { context = new mvCmsContext(); } private static Func<mvCmsContext, string, Configuration> _byName = CompiledQuery.Compile((mvCmsContext context, string configName) =>.........................
is it possible to have a button that points to a method you have defined in codebehind, that passes in a record from the row as a parameter? for example, id.something like:
Can the select command of a SqlDataSource be given by code in the code behind file. Also by calling the SqlDataSource.Select can the select statement be executed?
I want to bind an ObjectDataSource to a property in my asp page and I want to do it in the page's aspx code, not in code-behind. I've already done it in code-behind, as follows:
[Code]....
I'd prefer to get rid of the ugly code-behind and just do this in mark-up. Something like [Code]....
This gives me a run-time error: Cannot create an object of type 'System.Object' from its string representation 'SelectedBook' for the 'DataSource' property.Is there a way of doing this declaratively and not in code-behind? Further, what if what I want is to actually use a child property of the property in question? For example, if my Book object has a ReaderComments collection, can I databind to it decaratively in the aspx mark-up?
I've got a web app that uses a MS SQL Server 2008 database. Recently I made two copies of the database, one for ongoing development, the other for users to begin testing and evaluting the application.
I've got two seperate web applications now. I've changed the web.config of the 'test' version to point to the test DB, but it still seems to be using the previous version.
Is this cached somewhere? I've run IISRESET on the box, but the the 'test' version of my web app still seems to point to the wrong DB.
Assuming here that I have full control over the server.I'm looking for a sample code that would help me understand how to create a new virtual directory on the IIS pointing to say C:
We have an application that is currently required to be accessed using two authentication schemes, Forms Auth and Active Directory or NTLM / Windows Auth.The way the application is now, there are two IIS sites pointing to different folders with the same set of files, everything identical except the web.config.Before anyone flames me this was an inherited application, but nevertheless one I am now responsible for. We have an opportunity to do some refactoring and I'm trying to figure out the best way to proceed.
i would like to know if there's something wrong in this asp.net code:
mydatareader = mycmd.executeReader() if myDataReader.HasRow then // Do something end if myConnection.Close()
If i avoid to call a "MyDataReader.Close()" does the connection close anyway ? I ask this because i'm assuming that if call a "MyConn.Close" it automatically close the associated datareader... or am i wrong ?
My Web Application is hosted on Server A. My Database is hosted on Server B.
Server A and Server B are not on same network. How can i point my connection string to the database in this scenario? Can any one give an example for this kind of Connection String?
I have a gridview that when users click an asp:Button a confirmation box needs to appear. Inside that confirmation box, I want to include information from the gridview (DataKeyValues) that I can use in the codebehind to customize the confirmation message that pops up.
I got any error from the code, saying 'not all code path return a value', i suspect it is the catch block doesnt return a value. If so, what value should i return?