Daily Archives

Articles indexed Thursday June 17 2010

Page 13/121 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • C# and SQL - sub select from a table parameter

    - by Dr.HappyPants
    Below is a code snippet for passing a table as a parameter to a query that can be used in Sql Server 2008. I'm confused though about the "SELECT id.custid FROM @custids id". Why does it use id.custid and @custids id...? private static void datatable_example() { string [] custids = {"ALFKI", "BONAP", "CACTU", "FRANK"}; DataTable custid_list = new DataTable(); custid_list.Columns.Add("custid", typeof(String)); foreach (string custid in custids) { DataRow dr = custid_list.NewRow(); dr["custid"] = custid; custid_list.Rows.Add(dr); } using(SqlConnection cn = setup_connection()) { using(SqlCommand cmd = cn.CreateCommand()) { cmd.CommandText = @"SELECT C.CustomerID, C.CompanyName FROM Northwind.dbo.Customers C WHERE C.CustomerID IN (SELECT id.custid FROM @custids id)"; cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@custids", SqlDbType.Structured); cmd.Parameters["@custids"].Direction = ParameterDirection.Input; cmd.Parameters["@custids"].TypeName = "custid_list_tbltype"; cmd.Parameters["@custids"].Value = custid_list; using (SqlDataAdapter da = new SqlDataAdapter(cmd)) using (DataSet ds = new DataSet()) { da.Fill(ds); PrintDataSet(ds); } } }

    Read the article

  • Should I return IEnumerable<T> or IQueryable<T> from my DAL?

    - by Gary '-'
    I know this could be opinion, but I'm looking for best practices. As I understand, IQueryable implements IEnumerable, so in my DAL, I currently have method signatures like the following: IEnumerable<Product> GetProducts(); IEnumerable<Product> GetProductsByCategory(int cateogoryId); Product GetProduct(int productId); Should I be using IQueryable here? What are the pros and cons of either approach? Note that I am planning on using the Repository pattern so I will have a class like so: public class ProductRepository { DBDataContext db = new DBDataContext(<!-- connection string -->); public IEnumerable<Product> GetProductsNew(int daysOld) { return db.GetProducts() .Where(p => p.AddedDateTime > DateTime.Now.AddDays(-daysOld )); } } Should I change my IEnumerable<T> to IQueryable<T>? What advantages/disadvantages are there to one or the other?

    Read the article

  • How to setup custom CSS based on account settings in a Django site?

    - by sdolan
    So I'm writing a Django based website that allows users select a color scheme through an administration interface. I already have middleware/context processors that links the current request (based on domain) to the account. My question is how to dynamically serve the CSS with the account's custom color scheme. I see two options: Add a CSS block to the base template that overrides the styles w/variables passed in through a context processors. Use a custom URL (e.g. "/static/dynamic/css//styles.css") that gets routed to a view that grabs all the necessary values and creates the css file. I'm content with either option, but was wondering if anyone else out there has dealt with similar problems and could give some insight as to "Best Practices".

    Read the article

  • display the item in tdbmemo from combobox

    - by zizil
    i have combobox that have value category1 and category2...the category1 have items like pencil,food,magazine,newspaper... when i choose category1, i want to retrieve the items in tdbmemo.then the same items in tdbmemo i want to display in checklistbox...i dont know how to do...i use clcat.items.add to display the item but the items is not display procedure TfrmSysConfig.FillInCheckListClCat; var sTable : string; sqlCat : TIBOQuery; iIndex :integer; lstCat : TStringList; begin if tblMain.FieldByName('POS_ReceiptCatBreakDown').AsString <> '' then begin sqlCat := TIBOQuery.Create(nil); sqlCat.IB_Connection := dmMain.db; lstCat := TStringList.Create; try sqlCat.SQL.Text := 'SELECT code FROM ' + cboCategory.Value; sqlCat.Open; while not sqlCat.Eof do begin clCat.Items.Add( sqlCat.FieldByName( 'Code' ).AsString ); sqlCat.Next; end; finally lstCat.Free; sqlCat.Free; end; end; end;

    Read the article

  • vim - how am I suppose to read this command to remove all blanks at the end of a line

    - by whaley
    I happened across this page full of super useful and rather cryptic vim tips at http://rayninfo.co.uk/vimtips.html. I've tried a few of these and I understand what is happening enough to be able to parse it correctly in my head so that I can possibly recreate it later. One I'm having a hard time getting my head wrapped around though are the following two commands to remove all spaces from the end of every line :%s= *$== : delete end of line blanks :%s= \+$== : Same thing I'm interpreting %s as string replacement on every line in the file, but after that I am getting lost in what looks like some gnarly variation of :s and regex. I'm used to seeing and using :s/regex/replacement. But the above is super confusing. What do those above commands mean in english, step by step?

    Read the article

  • Is there a way to accept '%' as part of input that works both in python 2.6 & 3.0?

    - by bug11
    In 2.6, if I needed to accept input that allowed a percent sign (such as "foo % bar"), I used raw_input() which worked as expected. In 3.0, input() accomplishes that same (with raw_input() having left the building). As an exercise, I'm hoping that I can have a backward-compatible version that will work with both 2.6 and 3.0. When I use input() in 2.6 and enter "foo % bar", the following error is returned: File "<string>", line 1, in <module> NameError: name "foo" is not defined ...which is expected. Anyway to to accomplish acceptance of input containing a percent sign that works in both 2.6 and 3.0? Thx.

    Read the article

  • Hibernate, select by id or unique column

    - by Nican
    I am using hibernate for Java, and I want to be able to select users by id or by name from the database. Nice thing about Hibernate is that it caches the result by id, but I seem to be unable to make it cache by name. static Session openSession = Factory.openSession(); public static User GetUser(int Id) { return (User) openSession.get(User.class, new Integer(Id)); } public static User GetUser( String Name ){ return (User) openSession.createCriteria( User.class ). add( Restrictions.eq("username", Name) ). uniqueResult(); } If I use GetUser(1) many times, hibernate will only show that it executed the first time. But every time I use GetUser("user1"), hibernate shows that it is executing a new query to database. What would be the best way to have the string identifier be cached also?

    Read the article

  • Examples of usability disasters?

    - by Willie Wheeler
    Anybody have good examples of usability disasters? Here's an example. Hector is a manager with a large team. Department admin wants to send Hector a spreadsheet with his team's salaries. She types "Hector" in the Outlook "To:" field. It autocompletes to "Hector's Team" but she doesn't notice that until after she sends it.

    Read the article

  • iPhone: Core Data: Updating a pre-filled database in future app versions.

    - by Cuzog
    I am creating an app with a database of information that needs to be pre-filled. This data will change in future versions. In the same database, I also need to store user editable information since that user edited data directly relates to the pre-filled data. My question is, if I'm pre-filling the database by creating a duplicate data model in a second app and copying over the core data file before release, how would I handle updates to that data in future versions of the app without destroying the user's existing data? Do the core data migration methods handle this, or must I write custom methods to programatically handle the merge at first app launch?

    Read the article

  • 3 Things You Didn't Know About Your Website

    There may be lots of things you don't know about your website, but there are three really important points that all small businesses should be aware of if they want to get great results from their websites. 1. Quality, relevant content on your website can make or break a sale.

    Read the article

  • Multi-Select Dropdown with size of 1

    - by Thomas
    Is there any way of creating a combo box (<select>) with a size of 1? All the examples I can find allow for multiple selects but with a number of options visible at any one time. If this cannot be accomplished with bog standard HTML is it possible in a JS library such as JQuery?

    Read the article

  • SVN Path Based Authorization: Granting listing access but not read access

    - by Jim
    Hello, We're using path-based-authorization module for Apache SVN. It all works fine, except that when users try to check out code they have access to, their SVN clients get confused if they don't have at least read access to the parent directories - all the way up to root. It works, but some clients just get confused sometimes. Because SVN path-based-authorization is recursively applied, we don't want to give all users read access to root, because that would give them access to all source code in the repository. It would, however, be acceptable if users could get directory listings (just not actual lines of code) for the entire repository. This would prevent the svn clients from getting confused. Does any one know how to grant permissions to get directory listings without granting permissions to the actual contents of the files? Thanks!

    Read the article

  • When and why are you planning to upgrade to Python 3.0?

    - by Tomislav Mutak
    Python 3.0 (aka Python 3000, Py3k, etc) is now available. When and why are you planning on porting your project or code to the new Python? edit: I'm particularly interested in any features that don't exist in 2.6 that make porting worth it. Right now seems like a lot of negatives (x hasn't been ported yet), but I don't know what people see as the positives. Regarding "when", I'm interested in people's thoughts that the first step to porting is to have "excellent test coverage" which seems a bit optimistic for some projects.

    Read the article

  • How to create custom CSS "on the fly" based on account settings in a Django site?

    - by sdolan
    So I'm writing a Django based website that allows users select a color scheme through an administration interface. I already have middleware/context processors that links the current request (based on domain) to the account. My question is how to dynamically serve the CSS with the account's custom color scheme. I see two options: Add a CSS block to the base template that overrides the styles w/variables passed in through a context processors. Use a custom URL (e.g. "/static/dynamic/css//styles.css") that gets routed to a view that grabs all the necessary values and creates the css file. I'm content with either option, but was wondering if anyone else out there has dealt with similar problems and could give some insight as to "Best Practices".

    Read the article

  • Can't seem to get Prototype AJAX form validation to work in conjunction with Codeigniter

    - by MattB
    Is there some kind of trick involved? Here's how I would envision it working: 1) User tries submitting the form 2) Event.observe captures this and sends an AJAX request to a special validation URL (PHP using Codeigniter) 3) If no errors were returned, continue submitting the original form 4) If errors were found, cancel form submission and display Mostly, I can't seem to get a separate AJAX validation request to work as the form continues submitting. I could use Event.stop(event), but have not found a way to re-start the process if no validation errors exist from the validation call. I'd post code, but I have about 15 examples of things I've tried and it would just clutter this question. Any ideas? :-( I didn't think form validation would be this difficult. Many thanks, - Matt

    Read the article

  • what's the story with the android XML namespace?

    - by Peter vdL
    When you first use a name from the android XML namespace, you have to say where to find it, with an attribute in XML like this: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" However, that URL is a 404 - nothing found there. The android: namespace is actually included under the locally-installed SDK. So what's going on here? Why do I need to include a dead URL? Why doesn't the build system pick it up from the SDK like all the other libraries? Thanks, just looking for the back story on this. Peter

    Read the article

  • RCov with RSpec-2

    - by JoshReedSchramm
    I'm working with a bit of a bleeding edge rails app. Rails 3, RSpec 2, Rspec-Rails2. It seems as if RSpec2 doesn't include the spec:rcov rake task that RSpec 1 has. (at least it isn't there yet) Has anyone had any luck running rcov with rspec 2, or writing their own rake task to make this work?

    Read the article

  • Does a Postgresql dump create sequences that start with - or after - the last key?

    - by bennylope
    I recently created a SQL dump of a database behind a Django project, and after cleaning the SQL up a little bit was able to restore the DB and all of the data. The problem was the sequences were all mucked up. I tried adding a new user and generated the Python error IntegrityError: duplicate key violates unique constraint. Naturally I figured my SQL dump didn't restart the sequence. But it did: DROP SEQUENCE "auth_user_id_seq" CASCADE; CREATE SEQUENCE "auth_user_id_seq" INCREMENT 1 START 446 MAXVALUE 9223372036854775807 MINVALUE 1 CACHE 1; ALTER TABLE "auth_user_id_seq" OWNER TO "db_user"; I figured out that a repeated attempt at creating a user (or any new row in any table with existing data and such a sequence) allowed for successful object/row creation. That solved the pressing problem. But given that the last user ID in that table was 446 - the same start value in the sequence creation above - it looks like Postgresql was simply trying to start creating rows with that key. Does the SQL dump provide the wrong start key by 1? Or should I invoke some other command to start sequences after the given start ID? Keenly curious.

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >