1. DataGridView BeginEdit

    Date: 07/11/06     Keywords: no keywords

    Hi all, I'm working again with my datagridview, and I've come across a problem.

    When there is an error in the data the user enters in the cell, I'd like to tell them this, and then put the cell back into edit mode so they can fix it. Googling tells me to call the dgv's BeginEdit() method, but I do this, and nothing seems to happen. Any ideas?

    Source: http://community.livejournal.com/csharp/69353.html

  2. PerformanceCounter class

    Date: 07/09/06     Keywords: no keywords

    So here's a real C# question, since my last question, while admittedly not completely on-topic about C#, was deleted without explanation:

    I am using the PerformanceCounter class and its related classes to iterate through the available performance categories, counters, and instances on a user's machine. Obviously these things (especially instances) tend to appear and disappear as the machine is used (e.g. processes tend to spawn and de-spawn).

    My application is passively taking samples of some of the more interesting counters and storing them; at specified intervals it does some other things about which this post is not concerned.

    Is there any way to tell if a performance counter that previously existed no longer exists (other than the obvious try/catch block on the NextSample() or NextValue() call)?

    Thanks for any information

    Source: http://community.livejournal.com/csharp/69019.html

  3. Databinding to member objects

    Date: 07/09/06     Keywords: no keywords

    Is there a way to tell a control to bind to an object that's a propery of another object?

    Say for example, I have the following classes:

    public class Cat
    {
               public string Name;
               public Dog Enemy;
    }
    public class Dog
    {
               public string Name;
    }
    


    Is there a way to bind a control to someCat.Enemy.Name? I'm specifically using a DataGridViewTextBoxColumn, and I want to set the DataPropertyName (this is similar to using a DataGrid though).

    Please save me from having to load everything manually!

    Source: http://community.livejournal.com/csharp/68816.html

  4. Deregistering an event listener

    Date: 07/05/06     Keywords: no keywords

    If I register an object as an event listener for an event of another object like this:

        sendingObject.EventName += new DelegateName(this.EventHandlerMethod);

    I can deregister this eventlistener only by doing this:

        sendingObject.EventName -= new DelegateName(this.EventHandlerMethod);

    I now have the problem, that several classes (pages), that get instantiated and thrown away, register, but I also need to deregister them again. I don't want to implement a method in every class (there are dozens of them), so my idea was, that the controlling class sends a deregister to the briefcase object. This would be much simpler than to implement a deregister in every class. The problem is, that the pages aren't the only objects, that register as an event listener, so a EventName = null; is impossible, since it would also remove all listeners, that should remain as listeners.

    The event object (which is of the type of the delegate, e.g. EventHandler) has some nice properties and methods. The method GetInvocationList gives you an array of all registered objects... of type Delegate. But if you want to deregister, you need the event handler of the registered object (in the upper example the new DelegateName(this.EventHandlerMethod);). In an Delegate object of the array I can find the target (the registered object) and the MethodInfo of the event handler method.

    Does anyone have an idea how I can 'create' an event handler to deregister an object? And, no: it wouldn't help if I'd put the deregister in the base class of the pages. The briefcase object keeps a lot of different insurances, that can have several sub-insurances. A page can not only register at the briefcase, but also at the insurance and even at the sub-insurance. Since all insurances and sub-insurances derive from the same base class, it would be much easier to tell the base class to remove all listeners, that are pages.

    Source: http://community.livejournal.com/csharp/68463.html

  5. Changing test data

    Date: 06/30/06     Keywords: database

    How do you guys deal with test data that comes from a database? I've got unit tests running that check , for example that data is inserted, fetched, and updated from the database corrrectly, but obviously the data changes as it goes, which creates a lot of work (i.e., manually going in and changing all the expected values). There must be a less-retarded way to do this... any suggestions?

    Source: http://community.livejournal.com/csharp/68294.html

  6. nullable DateTimePicker

    Date: 06/28/06     Keywords: database, web

    I need to use a number of DateTimePicker controls on a Windows Forms 2.0 database-linked application that I'm putting together.

    The DateTimePicker control doesn't support null values, and despite trying to work around it for many hours and trying numerous 'solutions' found on the web, I'm still no closer to a fix than when I started.

    A null value for a date field in the database currently yields a control with todays date entered in.  Whereas it needs to be obvious in the application that no date has yet been entered.

    Also, if a record has say a birth date entered in, and then another record is switched to which has a null value for that birth date field, then the birth date field remains unchanged (making it appear that record 2 has the same birth date as record 1, even though in actuality - no birth date has yet been chosen for record 2).

    The variety of solutions on the web seem to be pretty much all pre-.Net 2.0, and don't have the desired result on .Net 2.0. 

    Can anyone help me out here?  Many thanks in advance!

    Source: http://community.livejournal.com/csharp/68011.html

  7. double databind

    Date: 06/27/06     Keywords: no keywords

    I have a mostly dynamic gridview. I have 2 columns that I've hard coded in. The rest are created on the fly.
    The new problem is that when I update a row, my changes don't show unless I redo my select statement (since I don't have it bound using the built-in datasource functionality). After I redo my select statement getting the updated row, I bind the grid, and it shows up. However, it is appending to the original data since I binded the grid earlier before the update. (Since its all dynamic I have to repopulate the grid on every postback). So now all my columns are showing up twice.

    Is there some way I can just set my dataSource, and have it update itself after I modify a row? Or a way to "unbind" the grid before I rebind it after the update?

    XX posted

    Thanks

    Source: http://community.livejournal.com/csharp/67622.html

  8. ASP.NET 2.0 Profiles

    Date: 06/23/06     Keywords: database, web, hosting

    I've got three questions.
    One - on user profiles.
    Two - on membership providers.
    Three - on the correctness of my general approach.

    So, here they go:

    1) I wrote the following code in Page_Load:

    string test_usr = "bush";
    string test_pwd = "george"; // that's why pentagon gets hacked
    string test_email = "bush@whitehouse.gov";

    Membership.CreateUser(test_usr, test_pwd, test_email);
    FormsAuthentication.Authenticate(test_usr, test_pwd);

    Profile["uid"] = "43"; // Error: the property cannot be set for anonimous user
    Profile["utype"] = "President";
    Response.Output.Write(Profile["uid"] + " " + Profile["utype"]);

    I pointed out an error in the comments above. I thought that once user is authenticated, it's assumed that I'm accessing him, when I use Profile. How do I do it properly? (Read a few articles, didn't find it.)

    2) A Membership Provider has the connection string, which tells authentication system where to store everything. Well, I went to that weird directory deep in VS.NET folders, and found the default provider, and edited it. Now membership works with my remote db properly. But, will it work when I move it to the website hosting? Doesn't seem to me that that file I edited will move along with the website. What do I do then?

    This is an approach question, if you have some time. :)
    3) We have a database of clients' data. This database, however, has no authentication fields, like passwords, usernames, and so on. I decided that authentication should be implemented separately, using Membership Providers. I've prepared a separate database for that purpose, edited the Provider, and tables were created perfectly. So I thought, I'm gonna use the User Profiles in order to store the client's id in the authentication database, which is the same id as the one stored in the client data db. This way I'm kind of connecting the two databases together. There are a couple of reasons I'm doing it. First - if I was to put all the data into User Profiles, without using separate database, it'd be slow and ineffective. Second - some clients are already in the database before they even registered on the website. (database is created independently of them). Therefore, if they do register, all I would need to do, is bind their authentication info to their actual data in the other database. Is this a good approach for the whole thing?

    Another long post, I know. Thanks for all the help so far!

    Source: http://community.livejournal.com/csharp/67218.html

  9. Rus.Only : Вышел АЛГОРИТМ №9

    Date: 06/23/06     Keywords: html, sql

    Содержание - http://dotnetgrains.sql.ru/alg/content7to9.html
    Скачать - http://dotnetgrains.sql.ru/alg/alg.htm

    Source: http://community.livejournal.com/csharp/67054.html

  10. Working with a screwed up database

    Date: 06/21/06     Keywords: database, sql

    Ok so now that I have my unions and memory issues resolved, now I need to fix this screwed up data that I have in my database.

    I have a badly created Document Control system that stores all the documents in the database in 2 tables: Current and Versioned (those are aliases.) Current obviously holds all the current documents and the Versioned table has all the old versions. The problem is though that not all the information corresponds with the correct records. For example, if you have 5 versions of a document, the version notes (which we use for ISO) for the most recent version (5) actually are associated with Version 4, along with the date it was submitted. Also, the original document version (1) has version notes and a submitted date with it as well, but obviously the first version can't have version notes so those are actually referring to the next version (2). If this sounds confusing its because it is. I don't know who designed this damn thing, but as a lesson let me say to NOT use Tribune's BMS content Management system for your document control because they don't do good database design and they blatantly steal their code from Wrox's "How to build an Intranet" book.

    So anyways I need to figure out how to get these records to correspond to the correct versions, so basically every record actually refers to the next record. Also it should be noted that SOME of the information does correspond, so I only need to move information from certain fields, not the entire row.


    SqlDataAdapter da = new SqlDataAdapter("SELECT d.mdItemID AS CurrentID, d.mdFileDescription AS CurrentFile, d.mdFileName as CurrentFileName, tblUser.usUserName AS Creator, " +
    "d.mdCreatedDate AS OriginalDocDate, tblMics_Docs_Versions.mvSubItemID AS OldID, " +
    "tblMics_Docs_Versions.mvFileName as OldFileName, usr2.usUserName as ModifiedBy, tblMics_Docs_Versions.mvNotes AS VersionNotes, " +
    "tblDepartment.dpNAME AS DepartmentName, tblMics_Docs_Versions.mvVersionedDate AS sort_date " +
    "FROM tblMics_Docs d INNER JOIN tblDepartment ON d.mdDepartmentID = tblDepartment.dpID " +
    "INNER JOIN tblUser On d.mdCreatedByUserID = tblUser.usUserID JOIN tblMics_Docs_Versions ON d.mdItemID = tblMics_Docs_Versions.mvItemID " +
    "INNER JOIN tblUser usr2 on tblMics_Docs_Versions.mvCheckedInByUserID = usr2.UsUserID " +
    "WHERE d.mdArchived = 0 UNION " +
    "SELECT d.mdItemID AS CurrentID, d.mdFileDescription AS CurrentFile, d.mdFileName as CurrentFileName, " +
    "tblUser.usUserName AS Creator, d.mdCreatedDate AS SubmittedDate, null, null, null, null, tblDepartment.dpNAME, getdate() as sort_date " +
    "FROM tblMics_Docs d INNER JOIN tblDepartment ON d.mdDepartmentID = tblDepartment.dpID " +
    "INNER JOIN tblUser On d.mdCreatedByUserID = tblUser.usUserID JOIN tblMics_Docs_Versions ON d.mdItemID = tblMics_Docs_Versions.mvItemID " +
    "INNER JOIN tblUser usr2 on tblMics_Docs_Versions.mvCheckedInByUserID = usr2.UsUserID WHERE d.mdArchived = 0 ORDER BY mdItemID ASC, sort_date ASC", con);

    try
    {
    da.Fill(ds);
    }

    catch (Exception j)
    {
    j.ToString();
    }

    ds.Tables[0].Columns.Add("Version");
    ds.Tables[0].Columns.Add("FileLocation");

    Int16 currID;
    int lastID = 0;
    int VerNum = 1;
    //This code below is used to add the version numbers to the documents because the CM system
    //Doesn't keep track and just uses a Count statement in its SQL code.

    foreach (DataRow dr in ds.Tables[0].Rows)
    {
    currID = System.Convert.ToInt16(dr["CurrentID"]);
    if ( currID == lastID )

    {
    dr["Version"] = VerNum;
    lastID = currID;
    }
    else
    {
    VerNum = 1;
    dr["Version"] = VerNum;
    lastID = currID;
    }
    if (dr["oldID"] == DBNull.Value )

    {
    dr["FileLocation"] = "BMS Current\\" + dr["DepartmentName"] + "\\" + dr["CurrentID"] + " Version " +
    dr["Version"] + " " + dr["CurrentFileName"];
    }
    else
    {
    dr["FileLocation"] = "BMS Archive\\" + dr["DepartmentName"] + "\\" + dr["CurrentID"] + " Version " +
    dr["Version"] + " " + dr["OldFileName"];
    }
    VerNum ++;
    }

    dg1.DataSource = ds.Tables[0];
    ds.Tables.Add("files");

    con.Close();
    //con.Dispose();
    ds.Dispose();
    da.Dispose();
    }

    I can try and post pictures of this in action if that'll help. Unfortunately my SQL skills aren't that good and I haven't had alot of experience with datasets. Thanks.

    Source: http://community.livejournal.com/csharp/66733.html

  11. A Collection of Objects (ArrayList, Hashtable, etc)

    Date: 06/20/06     Keywords: no keywords

    Hello,

    I'm trying to create a hashtable or arraylist of objects of classes, which I wrote myself earlier.

    so I have:

    class myClass
    {
    myClass()
    {
    //blah
    }

    myMethod()
    {
    //stuff
    }
    }

    myClass myClassInstance = new myClassInstance;
    ArrayList list = new ArrayList();

    list.Add(myClassInstance);

    // So here I'm trying to run a method from the list.

    list[0].myMethod();


    Here, I get an error, that an Object class does not have "myMethod". So, C# doesn't recognize that it's not an Object in the list, it's MyClass. How can I make a collection of my own objects, so that I can use their methods like that? Sounds like it has something to do with the rules of polymorphism in C#, which I don't know, as I'm used to template system of C++.

    Thanks.

    Source: http://community.livejournal.com/csharp/66322.html

  12. Total Newbie Question

    Date: 06/20/06     Keywords: programming

    Hi!

    I'm not *totally* new to Visual Studio, but I stopped concentrating on programming a long time ago, and now it's time to start again as I need things for my Uni course.

    So... I've just installed Visual Studio 2005 for the first time.
    And... I've got a nice book about C#.
    And it tells me to open up Visual Studio and select Visual C# Development Settings from the list it shows on the first time of opening VS.
    But... I opened it up earlier and wasn't sure about that list, so I just closed it. And that list isn't available anymore.
    But I followed the book's instructions, and it's definitely not a C# project.
    It seems to be in VB.

    So my question is, how do I get that list back to choose C#?

    I'm really sorry for the total newbie question. Hopefully I'll be asking more serious coding questions soon!

    Source: http://community.livejournal.com/csharp/66237.html

  13. C# program with memory issues

    Date: 06/20/06     Keywords: programming, database, sql, web

    I'm writing a program in C# 1.1 that extracts documents from our current database to be then transferred into our new content manager/collaborator or whatever. Anyways I have basically written the program and it successfully extracts the documents that I tell it to, but the problem is that its a major memory hog, and when I monitor the memory and the heap size it is just staggering. The problem is that I basically have loops that are going and grabbing sometimes hundreds of documents at a time, and when the documents are over 1mb in size it almost starts to get scary. I should also point out that I've never written a program like this before and I have learned more about programming and memory management than I ever cared to know. I don't know if there's anything I'm programming wrong, or if I'm not releasing resources correctly. My "expertise" is more in Web development than this, and it doesn't help that not alot of people at my company know C#. Anyways below is the code I have for grabbing multiple documents.

    {
    con.Open();

    SqlDataAdapter da = new SqlDataAdapter("Select * FROM tblMics_Docs_Versions WHERE mvItemID = " + number + " ORDER BY mvVersionedDate DESC", con);

    int i = 0;
    int j = 1;

    byte[] MyData = new byte[0];

    da.Fill(ds.Tables[1]);
    da.Dispose();

    DataRow myRow;

    for (i = 0; i <= ds.Tables[1].Rows.Count - 1; i++)
    {

    myRow=ds.Tables[1].Rows[i];
    MyData = (byte[])myRow["mvContent"];

    string thefile;

    string theid;

    thefile = myRow["mvFileName"].ToString();

    theid = myRow["mvItemID"].ToString();

    int ArraySize = new int();
    ArraySize = MyData.GetUpperBound(0);

    string s=System.IO.Path.Combine(dept, "ID " + theid + " Version " + j + " " + thefile);
    DirectoryInfo di = Directory.CreateDirectory(@"c:\BMS Old\" + dept);
    FileStream fs = new FileStream(@"C:\BMS Old\"+ s, FileMode.OpenOrCreate, FileAccess.Write);
    fs.Write(MyData, 0,ArraySize);

    fs.Close();



    myRow = null;
    MyData = null;
    j++;
    s = null;
    di = null;
    thefile = null;
    theid = null;

    }
    ds.Dispose();
    ds.Tables[1].Dispose();
    ds.Tables[1].Clear();

    con.Close();

    //con.Dispose();
    //con = null;
    }

    I'm sure this code isn't great, but at the very least it WORKS. Now I need to clean it up so we can run this in a production environment. Thank you.

    Source: http://community.livejournal.com/csharp/65808.html

  14. longshot

    Date: 06/19/06     Keywords: no keywords

    I just want to know if anyone here has any experience with creating dynamic template fields on the gridview control. I have to allow editing in my gridview, but all my columns are created dynamically and depending on what type of column it is, I will then put a dropdown or a textbox into the template field's edit area.
    I am a little in over my head right now and was just wondering if anyone else has been in this situation before so perhaps I could pick your brain...
    Thanks.

    Source: http://community.livejournal.com/csharp/65760.html

  15. Read-only dropbox

    Date: 06/15/06     Keywords: html

    I couldn't find a property in combobox that allows me to create a drop-down combo box that is not editable. I just need a regular drop-box like the ones created by html. Is there a sepearte control for it?

    Source: http://community.livejournal.com/csharp/65450.html

  16. TableAdapters and mapping parameters

    Date: 06/13/06     Keywords: asp, sql, microsoft

    Hello, guys. Experts-exchange couldn't help. Microsoft support couldn't help. Though, the problem seems easy to solve, just a technicality.

    When you program for ASP.NET 2.0, you can use TableAdapters in Visual Studio 2005 to connect your program with the stored procedures on the SQL Server 2005. Like, you need a function for getting a client by his id. You go to DataSet designer, and add a new TableAdapter. You choose the pre-made stored procedure in the "SELECT" field, and everything is perfect. Here's the problem: when you try to create a TableAdapter for "INSERT" or "UPDATE", it asks you to map the parameters to columns in some datatable. But even if I add a new datatable to the DataSet designer, and create columns corresponding to parameters in my stored procedure, I still can't select them when wizard asks me to map them. These colums are simply not there. How can I map something in my program to those Stored Procedure parameters through TableAdapter? Please, help.

    P.S. I realize this isn't an ASP or VS.NET community, but this subject is very popular within c# circles, so hope I'm not causing any inconvenience.

    Source: http://community.livejournal.com/csharp/65255.html

  17. dataset problem

    Date: 06/12/06     Keywords: database, sql

    I’m currently working with C# and SQLExpress 2005, and I’m doing some database stuff.

    I have a table that has two columns, [Index] and Descriptor. It looks like:

    0 Inactive
    1 Active
    etc.



    Relevant code:

    DataSet DS2 = new DataSet();

    //cbostatus is a combo box containing a list of descriptors that the user can choose from

    string getstat = "SELECT [Index] FROM status WHERE Descriptor = '" + cboStatus.Text + "';";

    conn.Open();
    SqlDataAdapter stat = new SqlDataAdapter(getstat, conn);
    stat.Fill(DS2);

    //The stat.Fill command should return a single value, since the sql query only returns 1 value

    int status = Convert.ToInt32((DS2.Tables[0].Rows[0]));

    // This is where I get an error, and the error is "InvalidCastException was unhandled Unable to cast object of type 'System.Data.DataRow' to type 'System.IConvertible'."

    conn.Close();


    Any ideas on how I can get this to return an int, or convert the dataset element to an int?

    Thanks!

    Source: http://community.livejournal.com/csharp/65023.html

  18. SQL INSERT

    Date: 06/03/06     Keywords: sql, web

    I'm getting an error on my sql INSERT statement where I’ve bolded.
    I just want to update one field called subject, and it keeps giving errors during debug.
    Can anyone tell me what might be wrong?

    Also, without using stored procedures, is this a good safe way to do an INSERT?


    protected void Button1_Click(object sender, EventArgs e)
    {
    string conn = string.Empty;
    ConnectionStringsSection connectionStringsSection = WebConfigurationManager.GetSection("connectionStrings") as ConnectionStringsSection;
    if (connectionStringsSection != null)
    {
    ConnectionStringSettingsCollection connectStrings = connectionStringsSection.ConnectionStrings;
    ConnectionStringSettings connString = connectStrings["defaultConnectionString"];
    conn = connString.ConnectionString;

    using ( SqlConnection connection = new SqlConnection(conn))
    using (SqlCommand command = new SqlCommand("INSERT into POST (subject) VALUES (@subject)", connection))
    {
    connection.Open();
    command.ExecuteQuery();
    connection.Close();
    }
    }

    }

    Source: http://community.livejournal.com/csharp/64748.html

  19. Please help

    Date: 06/02/06     Keywords: database, asp

    Hi All,
    As I was doing this tutorial on VS 2005 , at the very end of part one I have encountered a problem, When I dragged and dropped the stored procedure onto the Dataset design view, and then went to modify the partial class for the dataset the following code gave me an error when translated to C#:

    VB.Net
    Public Function SubmitRating(ByVal LinkID As Integer, ByVal NewRating As Integer) As Long
    Dim AvgRating As Long = 0 'output parameter returned
    AvgRating = taSP.LinkRatingVote(LinkID, NewRating, AvgRating)
    'update the avg rating in dataset
    Dim row As LinkRow = Link.FindByLinkID(LinkID)
    row.AvgRating = AvgRating
    row.EndEdit()
    row.AcceptChanges() 'no need to pass to the database
    End Function

    C#
    public long SubmitRating(int LinkID, int NewRating)
    {
    long AvgRating = 0;
    AvgRating = = taSP.LinkRatingVote(LinkID, NewRating, AvgRating)(LinkID, NewRating, AvgRating); Argument 3 cannot convert from long to ref int
    LinkRow row = Link.FindByLinkID(LinkID);
    row.AvgRating = AvgRating;
    row.EndEdit();
    row.AcceptChanges();

    }

    please help, what whould the correct code look like?
    Update: - I tried changing AvgRating to an int, and called LinkRatingVote as follows :- taSP.LinkRatingVote(LinkID, NewRating, ref
    AvgRating) I still had the same error saying the arguments aren't correct.

    Source: http://community.livejournal.com/csharp/64406.html

  20. C# jobs

    Date: 05/30/06     Keywords: asp

    I've been primarily a VB.NET/ASP.NET programmer for the past few years, previous to that I was a VB6/Access programmer for 7 years. I see the trend of many places moving to C#, so I'm wondering how much my VB.NET/ASP.NET experience would count if I were to play around with C# on my own for a few months and then apply for a C# position. I know it depends on the employer, but I'm wondering if anyone here has made that jump. Getting certified is not out of the question.

    Source: http://community.livejournal.com/csharp/64248.html

Previous page  ||  Next page


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home