Results 1 to 7 of 7

Thread: [RESOLVED] String argument causes problem

  1. #1

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Resolved [RESOLVED] String argument causes problem

    I have the ff. code...

    Code:
    public string GetNewID(string tableName)
    {
        const string stringSql = "SELECT CurrentValue FROM Sequences WHERE TableName = ?";
        _dataAccess.PrepareQuery(stringSql);
        //_dataAccess.AddParameter("TableName", (System.String)stringTableName);
        _dataAccess.AddWhereParameter("TableName", "EmployeeID");
        int result = (int)_dataAccess.GetFieldValue;
    
        // Since I am formating the result with 5 0's (00000) I have to check
        // whether I have reach passed 5 digit numbers, if I have then
        // I should reset it to one.
        if (result.Equals(100000))
        {
            const string stringUpdateSequence = "UPDATE Sequences SET CurrentValue = 1 WHERE TableName = ?";
            _dataAccess.PrepareQuery(stringUpdateSequence);
            _dataAccess.AddParameter("TableName", "EmployeeID");
            _dataAccess.ExecuteActionQuery();
        }
        int currentValue = _dataAccess.GetNextSequenceNumber("EmployeeID");            
        return string.Format("{0:yy-MM}-{1:00000}", DateTime.Now, currentValue);
    }
    t is called by:
    Code:
    public static string GetNewCode()
            {
                string newCode = _dataPortal.GetNewID("EmpoyeeID");
                return newCode;
            }
    If you may notice I have a parameter tableName which I intend to fill the value for the parameters I would pass like...

    Code:
    _dataAccess.AddWhereParameter("TableName", tableName);
    Problem is if I do that it causes an error, I can't get the ...

    Code:
    (int)_dataAccess.GetFieldValue
    To work since it is returning a null value, whereas if I hardcode it all is working well, what seems to be the problem? This is really strange...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: String argument causes problem

    I don't understand this:
    Code:
    _dataAccess.AddParameter("TableName", (System.String)stringTableName);
    Your argument is named 'tableName', not 'stringTableName', and it is already a String so why the cast?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: String argument causes problem

    Quote Originally Posted by jmcilhinney
    I don't understand this:
    Code:
    _dataAccess.AddParameter("TableName", (System.String)stringTableName);
    Your argument is named 'tableName', not 'stringTableName', and it is already a String so why the cast?
    Ooopppsss... That is commented out, was just trying to cast it to string if it would work, and I just changed the variable name, sorry if I didn't remove it...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: String argument causes problem

    So previously you were doing this:
    Code:
    _dataAccess.AddParameter("TableName", tableName);
    and it wouldn't work?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: String argument causes problem

    Yes, my method is returning null...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: String argument causes problem

    string newCode = _dataPortal.GetNewID("EmpoyeeID");
    Could it be that you can't spell?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: String argument causes problem

    Quote Originally Posted by jmcilhinney
    Could it be that you can't spell?


    My stomach is aching, you got it!!! Har, har, har!!!
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width