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
wwb
Aug 17, 2004

That is one the short list of classic Ajax applications.

There are three ways to tackle this:

1) Use MS Ajax Extensions. Pretty much a waste if this is the only AJAX powered thing you wish to do. Otoh, you could wire this up without writing a lick of javascript and they are loving awesome if you are doing alot of random ajax powered stuff.

2) Use a lighter-weight framework (My favorite is http://www.ajaxpro.info/). And write some javascript/some handlers.

3) If this is a quick, one-off, just write your own hand-tooled ajax bits. For something like this it is pretty easy. Just a bit o JS and a http handler to serve the list based on a query string parameter.

Adbot
ADBOT LOVES YOU

DarkPaladin
Feb 11, 2004
Death is just God's way of telling you you wasted your life.

JediGandalf posted:

I think I might have convinced the programming department @ school to use C#/.NET. Go me! However, they don't know a lick of C#, but they were very impressed with what they saw. I did a side-by-side comparison of the same program written in MFC and in C#. They liked how C# looked less menacing than MFC and easier to maintain.

If they choose my C# version (oh please oh please), what materials do you all recommend for them? They are all basically C++ people. One has some Java experience.

It's not to hard to pick up as long as you don't do anything like threading (simple in theory sure). There are a ton of internet tutorials out there. I'd expect your java guy to pick it up faster then the c++ guys but overall if you know a base language, it's one of the easiest to pick up.

Victor
Jun 18, 2004
DarkPaladin, surely a bit of AJAX would work? An asynchronous request could be fired when the first drop down is changed to get the contents of the second.

JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?

DarkPaladin posted:

It's not to hard to pick up as long as you don't do anything like threading (simple in theory sure). There are a ton of internet tutorials out there. I'd expect your java guy to pick it up faster then the c++ guys but overall if you know a base language, it's one of the easiest to pick up.
I do have one thread in the program. But it is not a complicated thread. It's a worker thread that doesn't rely on data outside the thread. So no thread saftey issues. I think they should be able to pick up the basics.

Gatto
Jul 12, 2003
Anyone have any experience with CodeSmith?

http://community.codesmithtools.com/blogs/tutorials/archive/2006/02/13/nettiers.aspx

I've been researching code generation tools to speed up developement. XSD seems a bit bulky for the need and does not appear to be easily modifiable.

A tool that help build skeletal templates of entity objects and data access layer can be a great boon.

What are your guys thoughts?

Ch00k
Feb 18, 2004
Chicken

Gatto posted:

Anyone have any experience with CodeSmith?
Yeah, I use CodeSmith to generate heaps of stuff. All data access layer and business layer. We are using custom templates, though in the dim dark ages they started life as CSLA templates. I havent had a problem with CodeSmith, but we are just generating whole files all the time, and using partial classing if we want to do anything fancy.

SLOSifl
Aug 10, 2002


I have to just jump in here to say this:

I love SQL CLR. I went from writing passable SQL daily to writing some really goood SQL stuff in a few minutes. I now have an entire System.IO complete filesystem written in two layers. A very powerful, "hands-on-data" SQL layer combined with a nice C# interface to complete an API. It's a bit of a pain to deploy a SQLCLR DLL though. If anyone at MS is listening - dropping 30 functions/SPs, upgrading a DLL and then ADDing is a bit annoying. I don't always have the option of deploying from my machine.

But really, writing SQL stored procedures in C# has made me amazingly happy. I don't know what the performance hit is, but I can lay some complicated SQL code down *right on the data* very quickly now.

LaptopGun
Sep 2, 2006

All I'm going to get out of him is a snappy one-liner and, if I'm real lucky, a brand new nickname.
I just wanted to give users of the x64 .Net a heads up. Microsoft Update was having issues installing .NET 3.0 x64 today. I expect them to be fixed by tomorrow, or at least by the time Microsoft has the next version of Windows out. :laugh:

wwb
Aug 17, 2004

Gatto posted:

Anyone have any experience with CodeSmith?

It rocks. I don't fully take advantage of it--I am not quite disciplined enough to get into a fully functional code generation scheme as part of the build process. But I do use it to write alot of guts of things. In any case, it paid for itself after it generated all 600 crud stored procs for one project.

Victor
Jun 18, 2004

Gatto posted:

Anyone have any experience with CodeSmith?

http://community.codesmithtools.com/blogs/tutorials/archive/2006/02/13/nettiers.aspx

I've been researching code generation tools to speed up developement. XSD seems a bit bulky for the need and does not appear to be easily modifiable.

A tool that help build skeletal templates of entity objects and data access layer can be a great boon.

What are your guys thoughts?
You are in luck (I hope) -- I think I was in a very similar position to you about a year ago. I had been following the practice of creating a class for every DB table I needed and using a single "Data Access Layer" (DAL) class to take care of CRUD operations and anything that involved SQL. I got tired of manually writing the table-wrapping classes, so I spent a bit of time designing a mini-DAL system. It included some base classes, one being DalConnection, which offers methods that remove the need to continually instantiate SqlCommand objects (you just call conn.ExecuteNonQuery). I create an log object for every bit of SQL executed so that if an exception occurs, I can see the SQL that caused it. I'm naughty and don't use parametrized SQL very often -- instead, I use a ToSqlString method which wraps its argument in single quotes and escapes all single quotes within the argument, or returns NULL if it were passed NULL. I know people think I'm an idiot for me, but it is quite foolproof -- the string '{0}' should never exist in the first argument to string.Format, it should always just be {0}. That way, the SQL has no chance of working when I test if I forget to call ToSqlString in the following arguments.

Anyways, I wrote a code generator based on proprietary templates, with a little GUI that is a limited version of Enterprise Manager, so that I could choose which DB columns to include, which to make writable, and which should be made parameters to my SelectSql method. The table-wrapping classes expose properties for all the DB columns (not OO, I know, but the pattern has worked so far), a constructor which takes a SqlDataReader, and four TSQL generating methods: SelectSql, DeleteSql, UpdateSql, InsertSql.

I can elaborate more if you would like. The above pattern has worked well so far; the strength is that I can customize the table-wrapping classes very easily; the weakness is that including more columns than originally is a bit of a pain, as I typically customize the class, making regenerating it from scratch not work very well. However, I have a feeling a bit of nifty merging action could solve that problem. I'll deal with it when it becomes an issue; most of the time, the only modifications I make are to the SelectSql method.

Oh, I've had no experience with CodeSmith. I just wrote my own code generator; I'm not sure CodeSmith has the flexibility to do what I implemented. I'm getting into more code generation these days, so perhaps I should look into it.

wwb
Aug 17, 2004

quote:

I can elaborate more if you would like. The above pattern has worked well so far; the strength is that I can customize the table-wrapping classes very easily; the weakness is that including more columns than originally is a bit of a pain, as I typically customize the class, making regenerating it from scratch not work very well. However, I have a feeling a bit of nifty merging action could solve that problem. I'll deal with it when it becomes an issue; most of the time, the only modifications I make are to the SelectSql method.

This is the downfall of code generation. Of course, .NET 2.0 and partial classes solves alot of this.

quote:

Oh, I've had no experience with CodeSmith. I just wrote my own code generator; I'm not sure CodeSmith has the flexibility to do what I implemented. I'm getting into more code generation these days, so perhaps I should look into it.

CodeSmith could have done this with ease.

Victor
Jun 18, 2004
wwb, your stating that CodeSmith allows this indicates to me that it is quite powerful, offering an API interface that basically takes care of templating for me so that I do not have to implement it myself. Instead, I can focus on the unique parts; is this the case?

I'm still working on the issues that cause this "downfall" of code generation. It involves more than just technology: I would need to separate issues of pure data access and business logic; currently I put them both in the same class. Hmmm, I think a light just went off in my head: perhaps I implement a layer between the table-wrapping classes and the classes that my application code accesses. I guess this is the 3-tier architecture (which never made a ton of sense to me, partly because I wanted to derive it instead of learn it)? I don't think I need to go this route yet, due to the nature of the applications I am writing. However, I think I just made a big personal discovery (of 3-tieredness); thanks for prompting that. :D

wwb
Aug 17, 2004

Yes, Codesmith is very, very sweet. Note you can try it for 30 days for free.

On the whole downfall, it is alot easier to get around with 2.0 because of partial classes. Basically, you can now have a MyClass.generated.cs (made by tool) and a MyClass.user.cs both compile to the same class. It is the same thing the VS designer does (MyForm.cs; MyForm.designer.cs for the tool generated stuff).

In 1.x you had to go the inherited classes route, which had some pitfalls--such as what if one wanted to inherit from a different class hierarchy.

As for the three tiered bit, I tend to let it straddle some these days. The data classes have some responsibilities, principally for data integrity and such. But major processes are split off into Manager classes which control the process. I help enforce this by making a fair part of the API internal so that you need to patch through the manager to do alot of things.

Victor
Jun 18, 2004
The partial class approach wouldn't work particularly well right now, due to how I generate my classes. Now that I think about it, a bit more abstraction might make this separation work out well. I came up with the data layer idea a while ago (frustratingly, I couldn't find the thread in the archives where I discussed it) and have used it for a while, so I have some good experience upon which to reflect. A coworker is also interested in using it; it needs to be reviewed and get some more documentation before that happens.

Edit: perhaps I should talk to my boss about open-sourcing the data layer code I have now. I like to think of it as a lightweight but extremely flexible base for those who like to see and exactly what goes on behind the scenes, instead of relying on O/R M magic, ahem, algorithms. The critique would probably be worth it as well.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



The talk about generated code has me wondering: does anyone have expierience with tools that take objects and generate databses from them?

As an example, right now I'm looking through the demo of DeveloperExpress and checking out its object to database conversion tool, which we think is a more logical solution than generating our objects to suit the database. It's also apparently able to taget 12 different popular databases, which seems like it will be great for portability. Are there significant drawbacks to this approach that I don't see?

genki
Nov 12, 2003

Munkeymon posted:

The talk about generated code has me wondering: does anyone have expierience with tools that take objects and generate databses from them?

As an example, right now I'm looking through the demo of DeveloperExpress and checking out its object to database conversion tool, which we think is a more logical solution than generating our objects to suit the database. It's also apparently able to taget 12 different popular databases, which seems like it will be great for portability. Are there significant drawbacks to this approach that I don't see?
The defacto tool for object persistence is Hibernate, afaik. The .NET version is called nHibernate.

What you're looking for is a ORM, object-relational mapper. There are a number of ORM solutions, and I would assume you have or will investigate more.

article with a lot of possible pitfalls of ORM:
http://www.codinghorror.com/blog/archives/000621.html

post regarding the difference between object persistence and data analysis:
http://jimcassidy.ca/2007/01/15/persistance-vs-analysis/

purely object oriented database possibility to look into:
http://www.db4o.com

edit: I just noticed db4o is linked in both articles. well, anyhow, look at it. :v:

Goon Matchmaker
Oct 23, 2003

I play too much EVE-Online
Someone please explain to me how two byte arrays that both contain { 0x15, 0x02, 0x04 } are not equal.

For reference here are some relevant code snippets:
code:
byte[] StartDelimiter = { 0x15, 0x02, 0x04 };

            for (int i = 0; i < Data.Count; i++)
            {
                if (buffer != StartDelimiter)
                {
                    buffer = ShiftBuffer(buffer, Data[i + 2]);
                    continue;
                }
            }

        private static byte[] ShiftBuffer(byte[] buffer, byte newbyte)
        {
            byte[] tmp = new byte[3];

            tmp[0] = buffer[1];
            tmp[1] = buffer[2];
            tmp[2] = newbyte;

            return tmp;
        }
I'm stepping byte by byte through a file of well byte values until I find the StartDelimiter and then I do some other voodoo that isn't up there in code. I've stepped through the code and seen it compare buffer and StartDelimiter twice now and hit the continue instead of going on down and doing the other stuff.

Goon Matchmaker fucked around with this message at 23:25 on Jan 31, 2007

genki
Nov 12, 2003

Safrax posted:

I'm stepping byte by byte through a file of well byte values until I find the StartDelimiter and then I do some other voodoo that isn't up there in code. I've stepped through the code and seen it compare buffer and StartDelimiter twice now and hit the continue instead of going on down and doing the other stuff.
I'm fairly positive the default '==' operation for an array compares the reference pointer, not the actual items in the array.

If you write a boolean function to actually compare every byte in the array, I suspect it would work as expected. It doesn't look like there's a default array comparison function.

Victor
Jun 18, 2004
genki is correct. You can reflect into different objects to see if they are class-types and if they do not override System.Object's equals operator. This is actually something [some of those on] the C# team wish they could have done differently -- it's confusing to have == sometimes test reference equality and sometimes test value equality. Too bad we won't have a language to overcome C#'s weaknesses like it did for some of Java's weaknesses for some time. I propose the name "Z==", which would be pronounced "zequals".

Goon Matchmaker
Oct 23, 2003

I play too much EVE-Online
:argh: Thanks genki and Victor. I guess I'll just have compare the 3 values in each array by hand.

Edit: Not by hand but by messy buffer[0] == DelimiterStart[0] junk.

Edit: Oh hey what do you know, it works now.

:argh:

Goon Matchmaker fucked around with this message at 23:40 on Jan 31, 2007

Gatto
Jul 12, 2003

Victor posted:

You are in luck (I hope) -- I think I was in a very similar position to you about a year ago. I had been following the practice of creating a class for every DB table I needed and using a single "Data Access Layer" (DAL) class to take care of CRUD operations and anything that involved SQL. I got tired of manually writing the table-wrapping classes, so I spent a bit of time designing a mini-DAL system. It included some base classes, one being DalConnection, which offers methods that remove the need to continually instantiate SqlCommand objects (you just call conn.ExecuteNonQuery). I create an log object for every bit of SQL executed so that if an exception occurs, I can see the SQL that caused it. I'm naughty and don't use parametrized SQL very often -- instead, I use a ToSqlString method which wraps its argument in single quotes and escapes all single quotes within the argument, or returns NULL if it were passed NULL. I know people think I'm an idiot for me, but it is quite foolproof -- the string '{0}' should never exist in the first argument to string.Format, it should always just be {0}. That way, the SQL has no chance of working when I test if I forget to call ToSqlString in the following arguments.

Anyways, I wrote a code generator based on proprietary templates, with a little GUI that is a limited version of Enterprise Manager, so that I could choose which DB columns to include, which to make writable, and which should be made parameters to my SelectSql method. The table-wrapping classes expose properties for all the DB columns (not OO, I know, but the pattern has worked so far), a constructor which takes a SqlDataReader, and four TSQL generating methods: SelectSql, DeleteSql, UpdateSql, InsertSql.

I can elaborate more if you would like. The above pattern has worked well so far; the strength is that I can customize the table-wrapping classes very easily; the weakness is that including more columns than originally is a bit of a pain, as I typically customize the class, making regenerating it from scratch not work very well. However, I have a feeling a bit of nifty merging action could solve that problem. I'll deal with it when it becomes an issue; most of the time, the only modifications I make are to the SelectSql method.

Oh, I've had no experience with CodeSmith. I just wrote my own code generator; I'm not sure CodeSmith has the flexibility to do what I implemented. I'm getting into more code generation these days, so perhaps I should look into it.

Your idea sounds pretty good. You put a lot thought behind it but I'm wondering why you didn't just use XSD to achieve some of what you were trying to do. I know the logging part can't be achieved but the robustness of xsd should make up for that fact.

What I don't think xsd is really good for is the n-tier programming model that some of us want to achieve. Separation of business objects and data layers.

Did you have any problems putting all data access in one class, it seems like to me if there were sufficient number of functions things can get unorganized.

Another thing I thinky our generation tool is pretty good but it doesn't generate stored procs into sql as codesmith would do. That's a nasty requirement that a code generation tool must have.

I would be interested into seeing more of your model and how you structured your code.

Codesmith seems to let you declare your own template files to do the generation. The template file contains structuring, syntax, and content info. So the flexibility is there, if you want to customize it to suit your code generation needs.

It does look pretty promising and indeed takes some of the tedious plumbing out of your work load.

Victor
Jun 18, 2004
Gatto, I didn't do any sort of stored procedure work, so you are probably best to go with CodeSmith. I didn't jump right into strongly typed data sets because they looked too "packaged" for my tastes. They might work well for 3-Tiered architecture, where only the data layer ever deals with the data sets, but I didn't want to go that way. My method has been working well so far, but it is pretty tightly coupled to a SQL database backend (it shouldn't be too hard to switch from MSSQL to something else). I'll see about posting a picture of the class diagram when I get into work this evening.

My biggest question for you is this: what do you want your data access code to look like? For some reason, I couldn't find much of this on the web when I was designing my DB layer, but I should think it would be a fairly important trait. If I were choosing between O/RMs and two products both satisfied my requirements, I would choose the one with the better glue code. Anyways, let us know what direction you take and perhaps some insights about the experience.

fankey
Aug 31, 2001

Just in case anyone is wrapping C++ with C++/CLR to use in C#, be warned that VS SP1 appears to break boost::threads. I have a simple network discovery library which spawns 1 boost::thread which I've wrapped up in a CLR object to use in my WPF app. After installing SP1 ( which apparently happened automatically!? ) and rebuilding both my app and boost, my program stopped working - I'd just get an error saying the image was bad. Uninstalling SP1 fixes the problem.

I reported this during the beta of SP1 but apparently they never bothered to fix it. My guess is that my old workaround of using the .dll version of boost::threads would probably still fix the problem.

Fiend
Dec 2, 2001
I'm using an HtmlTextWriter control to generate output. I can get server-side controls to render, but the event that I've assigned isn't firing.
code:
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
ImageButton ib = new ImageButton();
ib.ImageUrl = "http://www.goatse.cx/hello.jpg";
ib.Click += new ImageClickEventHandler(ib_Click);
ib.RenderControl(htw);

&hellip;

protected void ib_Click(object sender, ImageClickEventArgs e)
{
    throw new Exception("gibson hacked, flatten and reinstall.");
}
Perhaps I'm missing something, like a "Make Fiend less retarded" setting somewhere under Tools/Options?

Victor
Jun 18, 2004
Fiend, what are you trying to do? Where are you adding the ImageButton to the form? Why are you calling its RenderControl method, instead of letting The Page/parent control do it? Note that you will want to assign the click event handler before adding the control to its parent if you do it after Viewstate is loaded. The viewstate article I mentioned above explains in more detail.

Dromio
Oct 16, 2002
Sleeper
Here's an ugly one. I'm having trouble with generics and interfaces:

code:
public interface IChildObject
{
    Document ParentDocument{get;set;}
    void SetParentDirty();
}

public class Widget: IChildObject
{
    private Document _ParentDocument;
    public Document ParentDocument
    {
        get { return _ParentDocument;}
        set { _ParentDocument = value;}
    }

    private string _Shape;
    public string Shape
    {
        get { return _Shape; }
        set { _Shape = value; }
    }

    public void SetParentDirty()
    {
        _ParentDocument.IsDirty = true;
    }
}

public class ChildList<T> : List<IChildObject>  
{
    private Document _ParentDocument;
    public Document ParentDocument
    {
        get { return _ParentDocument;}
        set { _ParentDocument = value;}
    }

    public void Add(IChildObject Child)
    {
        Child.ParentDocument = _ParentDocument;
        base.Add(Child);
    }
}

public class BigWoozle
{
    private ChildList<Widget> _WidgetList = new ChildList<Widget>();
    public ChildList<Widget> WidgetList
    {
        get 
        {        
            return _WidgetList;
        }
        set
        {
            _WidgetList = value;
        }
    }
}

public static void TestList()
{
    BigWoozle WoozleInstance = new BigWoozle();
    Widget WidgetInstance = new Widget();
    WidgetInstance.Shape = "Square";
    WoozleInstance.WidgetList.Add(WidgetInstance);
    
    string RetrievedShape = WoozleInstance.WidgetList[0].Shape;  //BOOM CRASH
                           // -- IChildObject does not have .Shape
                           // Even though BigWoozle.WidgetList is ChildList<Widget>
}
I want a ChildList<T> where the T has to implement the IChildObject interface, but could be anything that implents IChildObject. Is this not possible?

SLOSifl
Aug 10, 2002


Dromio posted:

I want a ChildList<T> where the T has to implement the IChildObject interface, but could be anything that implents IChildObject. Is this not possible?
class ChildList<T> where T : IChildObject

http://msdn2.microsoft.com/en-us/library/d5x73970.aspx

It's so simple it's almost confusing.

Dromio
Oct 16, 2002
Sleeper
Oh thank you. I was having a hell of a time searching for "generics interface inheritance".

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

SLOSifl posted:

class ChildList<T> where T : IChildObject
code:
class ChildList<T> : List<T> where T : IChildObject
:v:

SLOSifl
Aug 10, 2002


Inquisitus posted:

code:
class ChildList<T> : List<T> where T : IChildObject
:v:
Eh, I originally typed

<T> where T : whatever

So at least I didn't totally give up.

wwb
Aug 17, 2004

^^^that can be handy, but you can really, really box yourself into corners using kinda sorta generic generics, especially when combined with inheritance. Be very careful where you use where. More often than not, you probably just need a traditional object that is written to an interface definition and not something tied to a generic. Especially where interfaces are involved.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
If I use an sqlcommand object and add parameters, how can I make the value of a parameter null? I want to update a field to null or insert nothing (and I have a fixed amount of data, I don't want to dynamically build the command text)

poopiehead
Oct 6, 2004

Nurbs posted:

If I use an sqlcommand object and add parameters, how can I make the value of a parameter null? I want to update a field to null or insert nothing (and I have a fixed amount of data, I don't want to dynamically build the command text)

Just add a null value. I forget the exact syntax but:

code:
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "InsertPossiblyNull";
cmd.Parameters.Add(new SqlParameter("@name",null));
cmd.ExecuteNonQuery();
For a stored procedure:

code:
CREATE PROCEDURE InsertPossiblyNull
@name varchar(20) = NULL
AS
INSERT INTO SomeTable
(name)
VALUES
(@name)
edit: in this example, you don't even have to actually add the parameter because the default would be null. But that should cover what you need to do anyway.

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

poopiehead posted:

Just add a null value. I forget the exact syntax but:

edit: in this example, you don't even have to actually add the parameter because the default would be null. But that should cover what you need to do anyway.

Thanks.

edit:

I do need to add parameter because I can't say insert this parameter if it isn't there?

I'm getting this error:

System.Data.SqlClient.SqlException was unhandled
Message="Parameterized Query '(@ID uniqueidentifier,@name nvarchar(36),@organizationTypeID uni' expects parameter @description, which was not supplied."

commandtext is

selectStatement = "SELECT ID FROM tableOrganization WHERE name = @name AND description = @description AND websiteAddress = @websiteAddress AND organizationTypeID = @organizationTypeID";

for an executescalar operation. (I'm checking to see if it already exists)

The following sets all the defaults. I have IF statements that change the values of the null parameters to data if its available. In the case of this error, these are all null.
sqlCommand.Parameters.AddWithValue("@ID", mediusOrganizationID);
sqlCommand.Parameters.AddWithValue("@name", emcOrganizationName);
sqlCommand.Parameters.AddWithValue("@organizationTypeID", mediusOrganizationTypeID);
sqlCommand.Parameters.AddWithValue("@creationDate", DateTime.Now);
sqlCommand.Parameters.AddWithValue("@creationUser", CommonVariables.userName);
//
sqlCommand.Parameters.AddWithValue("@description", null);
sqlCommand.Parameters.AddWithValue("@websiteAddress", null);
sqlCommand.Parameters.AddWithValue("@bsrNumber", null);
sqlCommand.Parameters.AddWithValue("@notes", null);

Nurbs fucked around with this message at 08:44 on Feb 3, 2007

Waffle Zone
Mar 17, 2004

by Y Kant Ozma Post
I've been looking into getting a C# book and learning C# to get back into programming. It has been a few years since I've programmed anything and my experience back then only took me up to the Programming AP test (Computer Science AB I think).

Are there any good in-depth tutorials online for a novice programmer? If not, what book would you recommend?

poopiehead
Oct 6, 2004

Nurbs posted:

Thanks.

edit:

I do need to add parameter because I can't say insert this parameter if it isn't there?

I'm getting this error:

System.Data.SqlClient.SqlException was unhandled
Message="Parameterized Query '(@ID uniqueidentifier,@name nvarchar(36),@organizationTypeID uni' expects parameter @description, which was not supplied."

commandtext is

selectStatement = "SELECT ID FROM tableOrganization WHERE name = @name AND description = @description AND websiteAddress = @websiteAddress AND organizationTypeID = @organizationTypeID";

for an executescalar operation. (I'm checking to see if it already exists)

The following sets all the defaults. I have IF statements that change the values of the null parameters to data if its available. In the case of this error, these are all null.
sqlCommand.Parameters.AddWithValue("@ID", mediusOrganizationID);
sqlCommand.Parameters.AddWithValue("@name", emcOrganizationName);
sqlCommand.Parameters.AddWithValue("@organizationTypeID", mediusOrganizationTypeID);
sqlCommand.Parameters.AddWithValue("@creationDate", DateTime.Now);
sqlCommand.Parameters.AddWithValue("@creationUser", CommonVariables.userName);
//
sqlCommand.Parameters.AddWithValue("@description", null);
sqlCommand.Parameters.AddWithValue("@websiteAddress", null);
sqlCommand.Parameters.AddWithValue("@bsrNumber", null);
sqlCommand.Parameters.AddWithValue("@notes", null);

try adding System.DBNull.Value. (again I'm probably off a bit with the spelling/name.).

sqlCommand.Parameters.AddWithValue("@notes", System.DBNull.Value);

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

Waffle Zone posted:

I've been looking into getting a C# book and learning C# to get back into programming. It has been a few years since I've programmed anything and my experience back then only took me up to the Programming AP test (Computer Science AB I think).

Are there any good in-depth tutorials online for a novice programmer? If not, what book would you recommend?
I used this book to introduce myself to C# and it worked just fine.

http://www.microsoft.com/mspress/books/5028.aspx

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

Waffle Zone posted:

I've been looking into getting a C# book and learning C# to get back into programming. It has been a few years since I've programmed anything and my experience back then only took me up to the Programming AP test (Computer Science AB I think).

Are there any good in-depth tutorials online for a novice programmer? If not, what book would you recommend?
This one's good:
http://www.amazon.com/Programming-C-Jesse-Liberty/dp/0596006993/sr=1-1/qid=1170549983/ref=pd_bbs_sr_1/002-8546920-4153610?ie=UTF8&s=books

SLOSifl
Aug 10, 2002


I'm not sure if this is necessary, but it's something I do a lot. When adding a null value to a SqlParameter, you need to go through a different process. If the value can be null, the structure I use looks like this:
code:
SqlParameter param = cmd.CreateParameter();
param.ParameterType = SqlDbType.Whatever;
patam.Size = 8000; // For varchar, nvarchar, varbinary
param.Value = valueVariable; // Can be null, or is null on purpose

cmd.Parameters.Add ( param ); // I forget this line more than any other
SQL strongly types variables but is generouse on implicit conversion. Null, unfortunately, infers no type information at all, and there is no conversion from null to null in SQL (null != null). System.DbNull.Value is just ANSI null so that won't work. Unless you are generating the value in that method, or checking for null before the assignment (cmd.Parameters.AddWithValue is preferred when you know it's not null), then use the strucutre I posted. If you're extremely lazy, you can always use varchar, nvarchar, or varbinary with a size that doesn't match the actual parameter for th etimes you don't know the actual size. 8000 is the max value, but not the same as varchar or varbinary (MAX). In that case, use SqlDbType.Image.

SLOSifl fucked around with this message at 09:13 on Feb 4, 2007

Adbot
ADBOT LOVES YOU

Darn Cotts
Mar 12, 2004

\Job"ber*nowl`\, n. [OE. jobbernoule, fr. jobarde a stupid fellow; cf. E. noll.] A blockhead. [Colloq. & Obs.]
I have a dialog that I basically want to stay "open" all the time - though its visibility can be toggled through an option in the "Windows" menu of my main form. The problem I'm having is that clicking the X in the control box at the top right of the dialog causes it to be closed and disposed. Is there any way to override this behaviour? I've tried overriding the OnClosing, OnClosed, OnFormClosing and OnFormClosed methods, but to no avail. I don't really want to hide the control box.

edit: Never mind, found the solution myself. Had to set the Cancel property of the Closing event to true :)

Darn Cotts fucked around with this message at 16:13 on Feb 4, 2007

  • Locked thread