Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
uXs
May 3, 2005

Mark it zero!
I have a problem with namespaces:

I'm working on a project (asp.net, c#), with several layers:
-The WebUI (= a website)
-A businessrules layer (= a class library)
-A datalayer (= a class library)

All layers are in seperate projects. There's also a third class library that contains the business objects. The datalayer gets stuff from the database, puts it in a business object, and passes them on to the business layer, which passes it to the WebUI. (All projects are different namespaces as well.)

Now the problem I'm having is that for a specific business object, the WebUI layer (sometimes) only recognizes them when I fully qualify it with the namespace.

Example:

code:
WeirdClass myObject = WeirdClassManager.GetItem(id_object_needed);
"WeirdClass" is located in the namespace Company.Project.BusinessObjects, and Intellisense recognizes it as such. The GetItem function (located in the business rules layer) returns an object of that same class. But when I try to compile it, I get the error "Cannot implicitly convert type 'Company.Project.BusinessObjects.WeirdClass' to 'WeirdClass'. When I add the namespace, it does work correctly:

code:
Company.Project.BusinessObjects.WeirdClass myObject = WeirdClassManager.GetItem(id_object_needed);
The page has a reference to the business objects project and a "using Company.Project.BusinessObjects" statement, so why wouldn't it work ? In fact, there are other classes, that work exactly the same way, for which it does work ! I compared the code for those classes, and I can't see any difference.

Same problem: when I declare an object of that class (without fully qualifying with the namespace), I can't even use its properties. Intellisense recognizes the object and shows the properties, but compiling tells me that "'WeirdClass' does not contain a definition for 'Id_weirdClass'". When I qualify it, it does work.

When I right-click the class, and do "go to definition", it shows me a definition generated "from metadata", that includes all the right properties, and is in the correct namespace. Fully qualifying the class, and then asking for the definition again, shows me exactly the same thing. But still the compiler thinks they're different.

I'm stumped. (I could just always name fully name them, but that annoys me.) Any ideas ?

Adbot
ADBOT LOVES YOU

uXs
May 3, 2005

Mark it zero!
Oh god yes thank you. I should've known it was something stupid like that. There was a webpage with that same name. (And webpages are classes as well in .NET.)

It didn't give the same error for the other object that did work correctly, because while there was also a page for that object, the capitalization was slightly different so there was no conflict there. :suicide:

Thanks ! (And now, weekend ! :toot: )

uXs
May 3, 2005

Mark it zero!
I'm doing an ASP.NET project where I have gridviews that show a list of records. These lists don't have to be edited. There are some columns where the value I have in the list is a foreign key. Naturally I want to display something else than a (for the user) meaningless key value.

What are some elegant methods of showing the user a value from the other table for each foreign key ? I'm using an objectdatasource as the datasource for the grid.

I was able to make a templatecolumn that has a dropdownlist, with another objectdatasource as the datasource, bound to the correct value. But using a dropdownlist in something that can't be edited is rather retarded. I want it to look like all the other columns, but with the value looked up from another table.

uXs
May 3, 2005

Mark it zero!

wwb posted:

What is underneath the ObjectDataSource? A typed dataset or a real object?

If it is a typed dataset, you could select the appropriate bits of the child table and then create a data relation and use that to hook up the rows and display pretty stuff.

If it is a real object, then things can be a bit trickier unless you want to "deep load" everything from the get go.

It's an object. I ended up putting the parts of the foreign table I want to view in the object itself. It seemed the easiest way and it's not that much overhead.

Perhaps I should make some functions that do get the extra info and some others that don't, to make it more maintainable, I dunno.

uXs
May 3, 2005

Mark it zero!

Dromio posted:

I'm having troubles with a session variable:

The user hits Default.aspx:
code:
protected void Page_Load(object sender, EventArgs e)
    {
    string CurrentSite = "Production";
    Session["CurrentSite"] = CurrentSite;
    Response.Redirect("TOC.aspx", false);
    }
But if I Trace.Write(CurrentSite) in TOC.aspx, it's always empty.
I thought adding "false" to the Redirect statement allowed it to set the session variables before moving on.

You are doing "string CurrentSite = (string) Session["CurrentSite"];" before you try to write it out, right ?

uXs
May 3, 2005

Mark it zero!

Stramit posted:

This is the connection string I am using (this does work locally):
code:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Restaurant.mdf;DataBase=NewRes;Trusted_Connection=Yes;
User Instance=False
...

I have checked the permissions on the App_Data on the IIS server and have granted the following users full access: ASPNET, NETWORK, NETWORK SERVICE. Am I missing any or is my SQL express just not configured right? I'm not an Microsoft SQL / IIS genius, and any help would be appreciated.

edit: Ubreaking tables

That AttachDBFilename thing in your connection string looked suspicious to me, so I went to check http://www.connectionstrings.com/?carrier=sqlserver2005. According to that page, the AttachDBFilename=whatever option only works for local SQL servers. So if you have seperate machines for IIS and SQL server (as I suppose you do), your connection string will not work.

From your error message, it looks like you're using the .NET sqlconnection, so your connectionstring should probably be something like: "Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;"

uXs
May 3, 2005

Mark it zero!
I have a gridview in asp.net 2.0. In this gridview are a whole lot of template columns, containing textboxes for editing. Depending on some variable, I need to be able to set some of the columns (= the textboxes in them) as readonly. I can't do this at design-time, because which columns should be readonly changes sometimes.

Is there an easy way to do it ? I think I can by finding the textbox controls upon the rowdatabound event, but that seems rather intensive. I'd like to set the entire column to readonly in one command, just like it's defined at design time in one place.

I've also been thinking about just generating the entire grid programmatically (would give me some other bonuses as well, like changing the number of columns), but that feels like it will give a performance hit as well.

Anyone here having experience with stuff like this who can give me some tips ?

uXs
May 3, 2005

Mark it zero!

Nurbs posted:

Nuts, no one else knows why my form mysteriously lost all of its controls, but all the code is still there and the designer file is intact (all of the controls are still declared and instantiated in it)?

This sounds close to what happens when you have databound controls and a designed dataset, and then you change the dataset. But in that case you should get an error message I think, and it is solved by just closing the form and opening it again.

Other possibility I can think of is also with databound controls, when the column name in a datagrid is the same as something else. But that should also give an error message somewhere.

Don't you get a message somewhere ? And does it still compile ? Or run ?

uXs
May 3, 2005

Mark it zero!

salithus posted:

Why doesn't this work?

code:
            connection.ConnectionString = GetConnectionString();
            connection.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT foo, bar FROM dbo.myTable ORDER BY 1;", connection);
            DataSet dataSet = new DataSet();
            dataAdapter.Fill(dataSet);
            connection.Close();
            dataGridView1.DataSource = dataSet.Tables[0];
            MessageBox.Show(dataSet.Tables[0].Rows.Count.ToString()); //gives 4000+
            MessageBox.Show(dataGridView1.RowCount.ToString()); //gives 0
I'm trying to get the dataGridView to show the results, but it's not. Using VC# Express and if it matters the SQL Server is 8.0.

I think you need to add a dataGridView1.DataBind(); command.

(Sidenote: I think you don't need to open or close the connection if you're using a dataAdapter. It doesn't hurt, but it's not needed, the adapter takes care of it.)

uXs
May 3, 2005

Mark it zero!

Dromio posted:

I hate FileSystemWatcher. It does EXACTLY what it's told to do, which is pretty useless for what most people want it to do.

It is firing the created event when the file is created, but whatever application created that file is still in the process of writing it. Yes, you could sleep a couple seconds and hope that gives it enough time to finish up, but what if it doesn't?

Or you can hack a while loop and catching the exceptions that are raised when you try to move it. But those exceptions can be awful expensive.

When I had to do it, I had to determine if a file was created, modified, or deleted, and act accordingly. I ended up with two threads, one running FileSystemWatcher and pumping descriptions of the various events into a queue, and other checking that queue and making sure no events had happened for the same file within the last 5 seconds before actually doing something. It was made even worse by the way MSOffice doesn't actually save over a file, it creates a temp file, saves to it, deletes the original, then renames the temp (or something like that).

I hate FileSystemWatcher. It had me so excited when I started .NET, and hurt me so bad.

http://www.nirsoft.net/utils/opened_files_view.html

This is a utility that lists file in use. It apparently uses windows APIs to do this. Maybe something like this will help ? It's probably a lot more work than just catching exceptions and letting your program wait a bit though.

uXs
May 3, 2005

Mark it zero!

salithus posted:

dataGridView1.DataBind(); gives me:

You're right, that doesn't exist.

I'm checking some code here and it seems that I'm using a BindingSource as an intermediate step. Try something like this:

BindingSource binding = new BindingSource();
binding.DataSource = yourDataTable;
yourDataGridView.DataSource = binding;

Failing that, try to give the table an explicit name, bind the bindingsource to the dataset instead of the table, and set binding.DataMember to that tablename. I don't think it's that, but that's the only other difference I'm seeing between my code and yours.

uXs
May 3, 2005

Mark it zero!

Munkeymon posted:

efb;


Try setting the <Binding Instance>.UpdateSourceTrigger as in:
code:
Binding tabBinding = new Binding("ControlCollection");
toolBinding.Source = stringCollection;
toolBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
scrollingItems.SetBinding(OrderChangingItemsControl.ItemsSourceProperty, toolBinding);

That shouldn't be necessary. You basically set the datasource to the datatable and that's it.

Maybe it's because you didn't define any columns ? I don't know why it doesn't generate them automatically though, it should do that.

uXs
May 3, 2005

Mark it zero!

salithus posted:

The DataGridView is working now. I realized I hadn't rebooted since last week :v:

Thanks for the pointers though. Is there a cleaner approach to what I'm doing though? I've got a listbox of products, and when I select a product, I want it to populate the datagrid. When the app loads, it's populating the product list and starts with the first one selected, so it should have that product line's data populated, but forcing the "SelectedIndexChanged" event seems too forceful.

You may be able to do it by doing the binding with master-detail databinding and using one bindingsource as the source for the other or something like that, instead of handling that in code.

Or put the code to fill the grid in a seperate function and call it when the form loads. You're still loading it manually one time when the app starts, but it feels less icky to me than calling the event handler or setting the selected index in code.

uXs
May 3, 2005

Mark it zero!

wwb posted:

What you do is make a new set of permissions and make that set fully trusted. Instructions are halfway down this page.

When I started to make .NET apps, I had problems with the permissions too. So I tried signing them and doing the permissions thing like you're supposed to do. But it's such a huge hassle that I just stopped doing that and now I'm just letting my programs be installed on either the user's PC or on the Citrix servers. In both cases I need some admin to install something, but at least they have experience with installing programs. They don't really with setting the .NET security policy.

So if you can avoid it by not running it from network drives, do so. Otherwise you'll have to do the security thing in the link above.

uXs
May 3, 2005

Mark it zero!
I have a gridview on a (fairly complicated) aspx page. In the HTML code that it spits out, a starting "div" tag is automatically generated right before the "table" tag. However, a matching closing "div" tag is not generated. Anyone have any idea what can be wrong here ? The missing tag is creating at least one problem and I'm guessing that it could be the cause of another one.

Edit: Never mind, found it. See this link for more details. Problem was using SetRenderMethodDelegate to render a gridview with multiple (merged) headers and having an error in the code to do it. Doing the change in the linked comment fixed it. (I'm using the simplified version by Mykola Tarasyuk linked to in another comment there btw.)

uXs fucked around with this message at 15:56 on Aug 13, 2007

uXs
May 3, 2005

Mark it zero!
I have several gridviews (asp.net) where I need to be able to hide the column with the "delete" button, depending on who is using the app.

Right now I'm using this code:

this.gridview.Columns[3].Visible = true;

I'm really bothered by having to use the column number, it's bound to cause problems down the line when someone adds a column somewhere and suddenly a whole bunch of users can now push the delete button. (I'm probably going to intercept the delete event and do an explicit check to avoid un-authorized deletes, but I still don't like it.)

Is there a way to indicate the column to hide with its name or something ?

uXs
May 3, 2005

Mark it zero!
For an ASP.NET app, I have the session start event retrieve user information, assign permissions to a User object, and store it in the session state.

To check what permissions someone should have, there are several Active Directory groups someone could be in. So I query the AD, and put the groups the user is a member of in a collection. Then, I need to check if the user is in group A and assign according permissions, check for group B and assign permissions, and so on.

The question is: what kind of collection do I put the groups in ? A StringCollection seems obvious, but is that fast enough ? Wouldn't a hashtable or something be better ? Or am I worrying too much again about irrelevant issues that aren't issues at all ?

uXs
May 3, 2005

Mark it zero!

wwb posted:

Probably worrying too much unless you have thousands of groups to check.

I would, however, look at making your user object implement IPrincipal and push said user into the Context.User property. That way you can rely on .NET's builtin security features to handle stuff. Such as using PrincipalPermissionAttribute on methods.

Ok thanks. I've had a quick look at IPrincipal and Context.User but it doesn't seem too useful for what I'm doing, the security checks are too complicated. Also the project is supposed to be finished at the end of next week so I don't really feel like changing it now. :v:

Made me realize (again) that there's still loads of things I don't know about asp.net though. Maybe I should take some overview course somewhere instead of just using google for everything ever.

uXs
May 3, 2005

Mark it zero!

havelock posted:

You can either do <%= MethodInYourCodeBehindThatReturnsTheStringOfJS() %> in your aspx, or output the whole js block via ClientScript.RegisterClientScriptBlock in your code behind.

Regardless of which method you use, I think it's a good idea to put the bulk of your javascript code in a separate .js file, and only put function calls in your aspx or aspx.cs files. Most examples on the internet seem to put all the javascript code in strings in the .cs file, which I think is a hilariously bad idea.

uXs
May 3, 2005

Mark it zero!
I am co-developing a fairly large intranet application. There are a number of pages where users do data entry, and obviously I'm doing several checks on the data before committing it.

I want the app to show the user in what fields an error was found, so I'm showing a little image next to those fields. They have a tooltip with the error message in it. There's also an area at the top of the page where all the error messages are shown as well.

We're using a custom control to handle the display of the images and the error area on top of the page.

Unfortunately, because we need to keep track what fields are giving the errors, the actual error checking is done in the aspx.cs-page of every entry form. I don't like this and would prefer it to be done somewhere else, in the objects themselves or a business rules tier or whatever. The error checking would work just fine there, but I have no idea what the best way would be to store in what fields the errors have occured.

Anyone here has a brilliant idea that doesn't involve storing too much extra data on what entry field correlates with what property of a business object ?

uXs
May 3, 2005

Mark it zero!

Roope posted:

What is the recommended naming scheme for Windows Forms controls? Is the Hungarian notation still being used? I haven't done Forms programming for ages and don't have a clue how to give meaningful and short names to monsters like toolStripMenuItem1. The code looks like disgusting mess with the long default names (ButtonMenuFileStripContainerItemViewBlahBlahObjectEtc123).

Normally I keep the control type in front, like TextBoxTitle or DropDownListMonth or whatever. But the names of controls in a menu or statusbar become way too long that way, so I shorten those to, for example, MenuMain and MenuEdit. Or perhaps MenuItemMain and MenuItemEdit, I dunno. Definitely not the ridiculously long default names though.

uXs fucked around with this message at 13:23 on Sep 22, 2007

uXs
May 3, 2005

Mark it zero!

wwb posted:

We use a variety of solutions depending on nature of the application. The large, industrial strength stuff flies off a home-brewed quasi ORM solution, largely for the same reasons lightbulbsun states. Biggest kicker is that most of the new, neato, augo-generated ORM solutions pretty much demand a 1-to-1 mapping of db to public properties, which might not make sense in some scenarios.

For lighter-weight stuff which is not quite so long-standing, we have started to use SubSonic. It is a very, very nifty solution. We are actually contemplating ripping out the ADO.NET bits of the home-brewed stuff and using SubSonic to manage the mechanical angles of persistence.

MS' new hawtness is LINQ. Which looks real neat, but I don't think it is quite ready for significant applications. See Rick Strahl's blog for some interesting 'features' he has found. More promising is the upcoming Entity Framework, which looks to be a very slick nHibernate killer.

I cannot claim to have ever used a Typed Dataset outside of a classroom scenario. We use DataSets internally in our homebrew framework--sometimes it is alot more efficent to load multiple tables in one hit. But they definitely don't ever get passed outside of the data tier.

I used datasets when I started out with .NET because it seemed like the obvious solution. Lately we've been using objects to pass data around with, and I like it a lot. I still use datasets in the latest project though, to be able to bind them to datagrids for very quick and dirty reporting. They're also easy to export to Excel for example. Using objects for that would be a lot slower to write. With datasets it's just basically writing a query, putting it in a dataset, and binding it to a grid.

uXs
May 3, 2005

Mark it zero!

FinkieMcGee posted:

C#/ASP.NET Caching question, as I'm a rookie and I'm trying to understand what the hell is going on.

So we have a database and we store lookup and mapping tables from there in our cache. Now, the way we cache in our database is kind of... odd, I think.

Basically we store each table as a datatable in a big Dictionary. Is this reasonable at all? I'm noticing a huge performance difference between going to our cached table, and going to the database for the same information. Going to the cache takes TWICE as long as going to the database!

Now I know that there is ACTUAL ASP.net caching, should I be using that, or is that not going to really yield a difference?

The way I used caching in this app I made is the following: everything (*) I read from the database is put in custom objects and generic lists of those objects. They got bound to dropdownlists and what have you with objectdatasources. Now for some dropdownlists that I needed a lot, I created a cache object that had functions to retrieve the lists from the cache (or retrieved them from the database and put them in the cache first if it didn't exist yet or was expired.)

So where normally it would ask some class to retrieve a list from the database, for those lists it would ask my cache class to retrieve the list from the cache. I don't really know if that improved performance really, but it was a neat thing to do :v:

Now I'm not really clear on how you're doing it. You're storing each table as a table in a Dictionary, but then what do you do with that Dictionary ? Are you putting that in the cache and retrieving it all the time ?

(*: There were, naturally, exceptions on this.)

Edit: ^^ Wait. That Dictionary is just in some static class ? I'm not 100% sure, but I think it's possible that the Dictionary is being recreated for every single call to the webserver. I doubt that it's persisted through postbacks, let alone sessions.

uXs fucked around with this message at 00:19 on Mar 19, 2008

uXs
May 3, 2005

Mark it zero!

LetoAtreides posted:

alright, here it is. Thing is, if I put cardgen() once outside the main method and then once inside the main method, it'll output two different cards

code:
        public void cardGen()
        {
            //deck array
            object[] deckArray = { "Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King" };

            //card type array
            string[] cardArray = { "Diamonds", "Spades", "Hearts", "Clubs" };

            //take a value from each array and combine it
            Random randomNumber = new Random();
            int number = randomNumber.Next(0, deckArray.Length);
            int card = randomNumber.Next(0, cardArray.Length);
            Console.WriteLine("Your card is {0} of {1}", deckArray[number], cardArray[card]);
        }


I think the problem is that you're making a new Random object each time you call your method. If you make 2 of them at practically the same instant, you can get the same "random" value.

The following would probably work better:

code:
public class RandomCardGenerator
  {
  private static Random randomNumber = new Random();

  public static void CardGen()
    {
    ...
    int number = randomNumber.Next(0, deckArray.Length);
    int card = randomNumber.Next(0, cardArray.Length);
    ...
    }
  }
And then you can call that with just:

code:
RandomCardGenerator.CardGen();
The first time the static method is invoked, it will create the Random object, and it will use the same object for subsequent calls to the method. Random is good for making series of random numbers, so the results will be random enough.

Code not tested in any way. Also I don't know how thread-safe this is, but I don't think you care.

uXs
May 3, 2005

Mark it zero!

notflipmo posted:

C# + .NET 3.5

Learn me some XML please :(

config.xml:
code:
<config>
	<limit>13312</limit>
	<interval>20</interval>
	<process>utorrent.exe</process>
	<process>dc++.exe</process>
</config>
Basically I would like to write readConfiguration(), which reads the file config.xml
and saves the limit and interval values to ints, and the process values to any suitable storeage class, most likely a string array since I don't expect more than a few process entries.

I figured it would be fun to use an XML configuration file in this project just to have used .NETs mechanisms for XML. But amongst XmlDocuments, XmlReaders, XmlElements, XmlNodes, my brain seems to have melted and I can't seem to grasp it.
I now feel exceedingly dense, after googling all day long and understanding very little :saddowns:

code:
        private void readConfiguration()
        {
            XmlDocument xd = new XmlDocument();
            xd.Load("config.xml");


        }

Beyond this, I haven't been able to make any sense of it all...

Two other options to work with XML if you're not hell-bent on doing it really manually:

* XmlSerializer. Very easy to do. You just put some attributes on a class, give the command to deserialize, and the file gets read and put into an object where you can do whatever.

* Linq to XML. Never used it, but it should work.

uXs
May 3, 2005

Mark it zero!

ray2k posted:

You could write a Visual Studio Addin that scans for those common scenarios and prevents a compile from passing if they are found. But it would be far more effort than, you know, remembering to actually dispose of things correctly the first time.

Can't you do this sort of thing in something like FxCop ? I've never used it or seen it closely, but I'm fairly sure it's a tool that can check code for compliance to all sorts of rules. Not closing connections seems like right up its alley. If you have a Team Foundation Server you could even make compliance required before you're allowed to check in code.

uXs
May 3, 2005

Mark it zero!

zero87t posted:

What does DataBind() do?

It binds data.

Maybe the confusion here is because you only have to do it in ASP.NET, and not in WinForms. Or maybe it's the other way around, I always forget.

uXs
May 3, 2005

Mark it zero!

Richard Noggin posted:

I don't believe there's an option to do that in the GD control panel.

It would help if you told us what your co-worker is trying to do. If he's trying to read what files are on the webserver, that sounds horribly insecure and I'm not in the least surprised that it's not allowed.

uXs
May 3, 2005

Mark it zero!

Richard Noggin posted:

This will be used to display random images from a directory on a web site. The directory is a subdirectory of the site (e.g. /images).

Is there any way you can keep a list of files, so you don't have to read the directory content ? It might be easier to do that than to gently caress around with permission problems. Those are hard enough when you have full control over the server, it will be even harder when you don't.

uXs
May 3, 2005

Mark it zero!
Also, there is no difference between the two. The compiler should compile it exactly the same. The first method is just easier to write and read (once you know what it does.)

uXs
May 3, 2005

Mark it zero!

cadmium posted:

Here's a question, I'm trying to use XmlSerializer on a class hierarchy. I'm trying to produce some simple xml for a 3rd party api. What I'm getting is close, but the XmlSerializer insists on junking it up with xsi/namespace crap:

code:
<Envelope [b]xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"[/b]>
  [b]<_body xsi:type="LoginBody">
    <Login xsi:type="LoginContent">...</Login>
  </_body>[/b]
  <Body [b]xsi:type="LoginBody"[/b]>
    <Login [b]xsi:type="LoginContent"[/b]>...</Login>
  </Body>
</Envelope>
I don't need to deserialize it, just fire and forget. How can I get stop it from adding that extra junk?

Weird. When I try to serialize things, it just puts <?xml version="1.0" encoding="utf-8"?> and <RootElementNameHere xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> at the top, and that's it. Can you post the code you use to serialize, and the class you're serializing ?

uXs
May 3, 2005

Mark it zero!

Uziel posted:

This is the error I get:
code:
Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error: 


Line 16:         FormViewDataSource.SelectParameters.Clear()
Line 17:         FormViewDataSource.SelectParameters.Add(New QueryStringParameter("?", "pkgcode"))
Line 18:         FormView1.DataBind()
Line 19: 
Line 20: 
 
Any ideas?

Is "pkgcode" supposed to be in quotes ? It looks like it should be a variable and you accidently put quotes around it.

uXs
May 3, 2005

Mark it zero!

Jethro posted:

From what I can tell, "pkgcode" is a string corresponding the name of the parameter in the request, i.e. blah.aspx?pkgcode=101, and the first string is the name of the parameter in the select query.

My first suggestion would be to give your parameter a name other than "?", in case ASP.NET or Access simply don't like that as a parameter name. Don't change the actual query, just change the part where you add the parameter to
code:
FormViewDataSource.SelectParameters.Add(New QueryStringParameter("pkgcode", "pkgcode"))

"FormViewDataSource.SelectParameters.Add(New QueryStringParameter("pkgcode", "pkgcode"))" will send "SELECT PackageName, Channel, PackageCode FROM DACPkgs WHERE Pkgcode = 'pkgcode'" to the database. "FormViewDataSource.SelectParameters.Add(New QueryStringParameter("pkgcode", pkgcode))" will give you, for example, "SELECT PackageName, Channel, PackageCode FROM DACPkgs WHERE Pkgcode = 5", which is probably what you want.

uXs
May 3, 2005

Mark it zero!

MORE CURLY FRIES posted:

How do I get a C# application to publish with an extra file dependency?

I've got a rules.xml file which I want to be attached to the project, but when I go to publish it it isn't there. I added the file on the "resources" pane, but no joy.

There's a "Copy to output directory" property for files, maybe that'll work.

uXs
May 3, 2005

Mark it zero!

Z-Bo posted:

Has anyone here leveraged XAML this way?

This post is pretty hilarious if you've just read the "corporate buzzwords" rant thread in GBS.

uXs
May 3, 2005

Mark it zero!

poopiehead posted:

It's as if every time it hits yield return, it adds the returned object to an enumerable and then at the end returns the whole thing.

Except that one of the neat things about yield is that it doesn't create intermediary, temporary lists. If you call something that uses yield, and you only iterate through the X first items, only those X items will be created in the yielding function. It does not create the entire list first and then return it, it just creates the ones you need, one item at a time, when you need that item.

So, saying that it's like making an enumerable first and then returning it may look like a good way of explaining it, but unfortunately it's wrong.

uXs
May 3, 2005

Mark it zero!
Linq to SQL, interfaces, ... question:

I'm getting a generic list of objects of type A from a database, with a function that first performs a Linq query and then does a queryResult.ToList() to return "List<A>".

A implements the interface IA. What I actually want to do is instead of returning a List<A>, is to return a List<IA>. (I want to use that list in other functions that should accept any List<IA>.) But then I get errors like "Cannot implicitly convert type 'A' to 'IA' at ..."

Any ideas ?

uXs
May 3, 2005

Mark it zero!

dwazegek posted:

queryResult.Cast<IA>().ToList()

Follow-up question:

I have the following interface/classes:

code:
namespace CastingTest
  {
  public interface ITest
    {
    string PropertyA { get; set; }
    }

  public class TestTarget : ITest
    {
    public string PropertyA { get; set; }
    
    public static explicit operator TestTarget(TestSource source)
      {
      TestTarget target = new TestTarget();
      target.PropertyA = source.PropertyA;

      return target;
      }
    }

  public class TestSource : ITest
    {
    public string PropertyA { get; set; }
    }
  }
I need to explicitly define the operator, otherwise the following doesn't compile:

code:
    [TestMethod]
    public void TestCast()
      {
      TestSource source = new TestSource();
      TestTarget target = (TestTarget) source;
      }
With the operator defined, it both compiles and passes/runs correctly.

code:
    [TestMethod]
    public void TestCastInterface()
      {
      ITest source = new TestSource();
      TestTarget target = (TestTarget)(source);
      }

    [TestMethod]
    public void TestCastInterfaceFixed()
      {
      ITest source = new TestSource();
      TestTarget target = (TestTarget)((TestSource)source);
      }
TestCastInterface compiles, but throws an InvalidCastException. TestCastInterfaceFixed both compiles and runs.

In the following code however, everything throws an InvalidCastException, and I don't know why. It seems that the Cast() function can't work with user-defined conversions or something. Any ideas ?

code:
    [TestMethod]
    public void TestListCast()
      {
      List<TestSource> sourceList = new List<TestSource>();
      sourceList.Add(new TestSource());
      sourceList.Add(new TestSource());

      IEnumerable<TestTarget> targetIEnum = sourceList.Cast<TestTarget>();
      List<TestTarget> targetList = targetIEnum.ToList();
      }

    [TestMethod]
    public void TestListCastInterface()
      {
      List<ITest> sourceList = new List<ITest>();
      sourceList.Add(new TestSource());
      sourceList.Add(new TestSource());

      IEnumerable<TestTarget> targetIEnum = sourceList.Cast<TestTarget>();
      List<TestTarget> targetList = targetIEnum.ToList();
      }

    [TestMethod]
    public void TestListCastInterfaceFixed()
      {
      List<ITest> sourceList = new List<ITest>();
      sourceList.Add(new TestSource());
      sourceList.Add(new TestSource());

      IEnumerable<TestTarget> targetIEnum = sourceList.Cast<TestSource>().Cast<TestTarget>();
      List<TestTarget> targetList = targetIEnum.ToList();
      }
(Edit: defining the conversion as implicit doesn't help.)

uXs fucked around with this message at 10:25 on Jul 9, 2008

uXs
May 3, 2005

Mark it zero!

dwazegek posted:

Casting is not the same as an explicit conversion, even though the syntax is identical.

In this case you'd have to use a Select instead of a cast, so something like:
code:
IEnumerable<TestTarget> targets = sourceList.Select(ts => (TestTarget)ts);

Cool, thanks. Having to do stuff like that makes me feel that there is probably something wrong with the design, but whatever. Thanks :-)

Adbot
ADBOT LOVES YOU

uXs
May 3, 2005

Mark it zero!

MORE CURLY FRIES posted:

Yeah, getting the info out of the database isn't the issue, it's the live updating of the page as the slower responses come back to the user.

I'd try splitting this up: one page that is shown to the user, and three that are basically just XML with the data. Using Javascript and a HttpRequest thingie, you can do the requests for data, and attach a callback function to each request. When the data is ready, use Javascript to show it to the user.

This is basically Ajax, but done in a rather manual way.

  • Locked thread