Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:24:27+00:00 2026-06-05T13:24:27+00:00

I tested this method for the string parameter alone, and it worked perfectly. So

  • 0

I tested this method for the string parameter alone, and it worked perfectly. So I am sure there is a mistake in setting up the parameter of type DateTime (datapubl), which I added later. Thank you in advance!

By the way, the CatalogCreateFilmsTest sproc was executed and works OK.

Anna

public static bool CreateFilmTest(string nume, string datapubl)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "CatalogCreateFilmTest";

            DbParameter param = com.CreateParameter();
            param.ParameterName = "@nume";
            param.Value = nume;
            param.DbType = DbType.String;
            param.Size = 200;
            com.Parameters.Add(param);

            param = com.CreateParameter();
            param.ParameterName = "@datapubl";
            param.Value = datapubl;
            param.DbType = DbType.DateTime;
            com.Parameters.Add(param);


            int result = -1;

            try
            {
                result = GenericDataAccess.ExecuteNonQuery(com);

            }
            catch
            {
                // 
            }

            return (result >= 1);

        }

EDIT: The problem is the stored procedure is not even executed (it should insert rows into a table but doesn’t) . No error, but not the correct result either.

EDIT: Chris, here is the full example:

CREATE PROCEDURE CatalogCreateFilmTest(
@nume nvarchar(1500),
@datapubl datetime
)
AS
INSERT INTO Filme
(nume, datapubl) 
VALUES
(@nume, @datapubl)
;
GO

which works for:

EXEC CatalogCreateFilmTest 'achu', '';

I then call CreateFilmTest like this:

bool success = FilmsAccess.CreateFilmTest(newNume.Text, null);

or:

bool success = FilmsAccess.CreateFilmTest(newNume.Text, DateTime.Now.ToString());

In both cases, the ExecuteNonQuery doesn’t run.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:24:28+00:00Added an answer on June 5, 2026 at 1:24 pm

    I don’t believe you can reuse the same variable due to the reference in the collection…

            DbParameter param1 = com.CreateParameter(); 
            param1.ParameterName = "@nume"; 
            param1.Value = nume; 
            param1.DbType = DbType.String; 
            param1.Size = 200; 
            com.Parameters.Add(param1); 
    
    
            DbParameter param2 = com.CreateParameter(); 
            param2.ParameterName = "@datapubl"; 
            param2.Value = datapubl; 
            param2.DbType = DbType.DateTime; 
            com.Parameters.Add(param2); 
    

    Also note, that you can use syntax like so with .net 4 (and maybe 3.5 too).

    com.Parameters.Add(
      com.CreateParameter()
      { 
        ParameterName = "@datapubl", 
        Value = datapubl, 
        DbType = DbType.DateTime
      }
    );
    

    It also might help to know what the exception is by filling in your catch block:

    catch(Exception ex)
    { 
      System.Diagnostics.Debug.WriteLine(ex.Message); 
    } 
    

    EDIT:

    I believe I see the issue now… (and should have seen it before).

    Change your method signature to:

    public static bool CreateFilmTest(string nume, DateTime datapubl) 
    

    And try executing the following:

    bool success = FilmsAccess.CreateFilmTest(newNume.Text, DateTime.Now); 
    

    To pass null, you’ll have to pass Convert.DbNull provided your column allows null.

    In order to pass strings as DateTime values, you’ll have to format them a specific way, i.e. YYYYMMDD however, I recommend letting the underlying DbCommand object take care of that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simplest fool proof(?) method to check for string object I've seen. Tested with many
This method: public static string[] getKeywords(string filename) { string[] keywords = XElement.Load(filename).Elements(Keyword).Attributes(name).Select(n => n.Value).ToArray
I know this particular query works, as I tested it with unprepared, procedural methods.
I have tested this servlet and it works well, except in Google Chrome it
When I tested this code, it gave me java.lang.ArrayIndexOutOfBoundsException: 2 The code isn't finished
I had tested this code: http://support.microsoft.com/kb/316383 It works, but a Word application is opened
I've tested this on Win XP and Windows Server 2008 R2 in Powershell 2.0:
This problem exists for webkit browsers only chrome and possibly safari (i've not tested
I have this method and it's kind of really big so I can't include
Possible Duplicate: Parse query string into an array What's the fastest method , to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.