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 7163993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:59:43+00:00 2026-05-28T13:59:43+00:00

Just as a little heads up, I’m completely new to this whole coding thing

  • 0

Just as a little heads up, I’m completely new to this whole “coding” thing in general, so forgive me if I don’t make myself clear and just let me know if I can tell you anything else. I’ve been Googling for days and couldn’t find anything, I’m not sure if that’s just bad on my part, or just because I’m really new and wouldn’t know the solution if it were right in front of my face.

When I go to test the application (Visual Studio 2010), everything shows up and I can put in information in my text boxes, but once I press submit, this error pops up:

“The OdbcParameterCollection only accepts non-null OdbcParameter type objects. Parameter name: value”

and it points to this line of code:

cmd.Parameters.Add(pram[i]);

I don’t know if I’m setting the parameters wrong or INSERT INTO statement wrong or what. I can show you the ASP.net code also if needed. Let me know if I can give you any more info! Thank you in advanced!

My C# code is this:

 private void execution(string eventspecialist, string phone, string phone2, string firstname, string lastname, string besttime, string companyname, string nonprofit, string requesteddate, string requestedtime, string attendance, string eventtype, string other, string leadsource, string notes, string catering, string bar, string damagedeposit, string dancefloor)
{


    OdbcConnection conn = new OdbcConnection(GetConnectionString());

    string sql = "INSERT INTO tblcontacts (eventspecialist, phone, phone2, firstname, lastname, besttime, companyname, nonprofit, requesteddate, requestedtime, attendance, eventtype, other, leadsource, notes, catering, bar, damagedeposit, dancefloor) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

    try
    {
        conn.Open();
        OdbcCommand cmd = new OdbcCommand(sql, conn);

        cmd.Parameters.Add("@SPECIALIST", OdbcType.NVarChar, 50).Value = eventspecialist;
        cmd.Parameters.Add("@CUST_PHONE1", OdbcType.NVarChar, 50).Value = phone;
        cmd.Parameters.Add("@CUST_PHONE2", OdbcType.NVarChar, 50).Value = phone2;
        cmd.Parameters.Add("@CUST_FNAME", OdbcType.NVarChar, 50).Value = firstname;
        cmd.Parameters.Add("@CUST_LNAME", OdbcType.NVarChar, 50).Value = lastname;
        cmd.Parameters.Add("@BEST_TIME", OdbcType.NVarChar, 50).Value = besttime;
        cmd.Parameters.Add("@COMPANY_NAME", OdbcType.NVarChar, 225).Value = companyname;
        cmd.Parameters.Add("@NONPROFIT", OdbcType.NVarChar, 1).Value = nonprofit;
        cmd.Parameters.Add("@REQ_DATE", OdbcType.NVarChar, 10).Value = requesteddate;
        cmd.Parameters.Add("@REQ_TIME", OdbcType.NVarChar, 20).Value = requestedtime;
        cmd.Parameters.Add("@ATTENDANCE", OdbcType.NVarChar, 50).Value = attendance;
        cmd.Parameters.Add("@EVENT_TYPE", OdbcType.NVarChar, 50).Value = eventtype;
        cmd.Parameters.Add("@OTHER_DESC", OdbcType.NVarChar, 225).Value = other;
        cmd.Parameters.Add("@LEAD_SOURCE", OdbcType.NVarChar, 50).Value = leadsource;
        cmd.Parameters.Add("@NOTES", OdbcType.NVarChar, 225).Value = notes;
        cmd.Parameters.Add("@CATERING", OdbcType.NVarChar, 1).Value = catering;
        cmd.Parameters.Add("@BAR", OdbcType.NVarChar, 1).Value = bar;
        cmd.Parameters.Add("@DAMAGE_DEPOSIT", OdbcType.NVarChar, 19).Value = damagedeposit;
        cmd.Parameters.Add("@DANCE_FLOOR", OdbcType.NVarChar, 19).Value = dancefloor;



        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();
    }
    catch (System.Data.Odbc.OdbcException ex_msg)
    {

        string msg = "Error occured while inserting";
        msg += ex_msg.Message;
        throw new Exception(msg);
    }
    finally
    {

        conn.Close();
    }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void submit_Click(object sender, EventArgs e)
{
    execution(eventspecialist.Text, phone.Text, phone2.Text, firstname.Text, lastname.Text, besttime.SelectedItem.Text, companyname.Text, nonprofit.Text, requesteddate.Text, requestedtime.Text, attendance.Text, eventtype.SelectedItem.Text, other.Text, leadsource.SelectedItem.Text, notes.Text, catering.Text, bar.Text, damagedeposit.Text, dancefloor.SelectedItem.Text);

    conform.Visible = true;
    Control frm = this.FindControl("form1");
    foreach (Control ctrl in frm.Controls)
    {
        if (ctrl is TextBox)
        {
            ((TextBox)ctrl).Text = "";
        }
        else if (ctrl is CheckBox)
        {
            ((CheckBox)ctrl).Checked = false;
        }
        else if (ctrl is DropDownList)
        {
            ((DropDownList)ctrl).SelectedIndex = 0;
        }
    }
}
  • 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-05-28T13:59:44+00:00Added an answer on May 28, 2026 at 1:59 pm

    You’re getting a null reference because you’ve created and set the size of pram but have not added any objects to it. So, what you have is an array filled with nulls. It looks like you can eliminate the for loop and the pram array altogether, because you’re adding the parameters to cmd already, outside the loop.

    The following code is unnecessary:

    OdbcParameter[] pram = new OdbcParameter[19];
    

    and also

    for (int i = 0; i < pram.Length; i++)
    {
        cmd.Parameters.Add(pram[i]);
    }
    

    Additionally, you should set the values of each parameter in this fashion:

    cmd.Parameters.Add("@SPECIALIST", OdbcType.NVarChar, 50).Value = eventspecialist;
    

    So, your try block will look like this:

    try
    {
        conn.Open();
        OdbcCommand cmd = new OdbcCommand(sql, conn);
    
        cmd.Parameters.Add("@SPECIALIST", OdbcType.NVarChar, 50).Value = eventspecialist;
        cmd.Parameters.Add("@CUST_PHONE1", OdbcType.NVarChar, 50).Value = phone;
        cmd.Parameters.Add("@CUST_PHONE2", OdbcType.NVarChar, 50).Value = phone2;
        cmd.Parameters.Add("@CUST_FNAME", OdbcType.NVarChar, 50).Value = firstname;
        cmd.Parameters.Add("@CUST_LNAME", OdbcType.NVarChar, 50).Value = lastname;
        cmd.Parameters.Add("@BEST_TIME", OdbcType.NVarChar, 50).Value = besttime;
        cmd.Parameters.Add("@COMPANY_NAME", OdbcType.NVarChar, 225).Value = companyname;
        cmd.Parameters.Add("@NONPROFIT", OdbcType.NVarChar, 1).Value = nonprofit;
        cmd.Parameters.Add("@REQ_DATE", OdbcType.Date, 10).Value = requesteddate;
        cmd.Parameters.Add("@REQ_TIME", OdbcType.Time, 20).Value = requestedtime;
        cmd.Parameters.Add("@ATTENDANCE", OdbcType.NVarChar, 50).Value = attendance;
        cmd.Parameters.Add("@EVENT_TYPE", OdbcType.NVarChar, 50).Value = eventtype;
        cmd.Parameters.Add("@OTHER_DESC", OdbcType.NVarChar, 225).Value = other;
        cmd.Parameters.Add("@LEAD_SOURCE", OdbcType.NVarChar, 50).Value = leadsource;
        cmd.Parameters.Add("@NOTES", OdbcType.NVarChar, 225).Value = notes;
        cmd.Parameters.Add("@CATERING", OdbcType.NVarChar, 1).Value = catering;
        cmd.Parameters.Add("@BAR", OdbcType.NVarChar, 1).Value = bar;
        cmd.Parameters.Add("@DAMAGE_DEPOSIT", OdbcType.NVarChar, 19).Value = damagedeposit;
        cmd.Parameters.Add("@DANCE_FLOOR", OdbcType.NVarChar, 19).Value = dancefloor;
    
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();
    
    }
    

    From your question’s edit, I see this is the code you’re using, and I take it you’re still getting the same error? This most likely means that one of the values you’re adding to the parameters collection is null. If you inspect them with the debugger, do they all have values set?

    Edit, again:

    There’s another error which I missed before. The SQL command you’ve written for ODBC is using parameters incorrectly, as indicated by the new error.

    string sql = "INSERT INTO tblcontacts (eventspecialist, phone, phone2, firstname, lastname, besttime, companyname, nonprofit, requesteddate, requestedtime, attendance, eventtype, other, leadsource, notes, catering, bar, damagedeposit, dancefloor) 
    VALUES (@SPECIALIST, @CUST_PHONE1, @CUST_PHONE2, @CUST_FNAME, @CUST_LNAME, @BEST_TIME, @COMPANY_NAME, @NONPROFIT, @REQ_DATE, @REQ_TIME, @ATTENDANCE, @EVENT_TYPE, @OTHER_DESC, @LEAD_SOURCE, @NOTES, @CATERING, @BAR, @DAMAGE_DEPOSIT, @DANCE_FLOOR)";
    

    Should be:

    string sql = "INSERT INTO tblcontacts (eventspecialist, phone, phone2, firstname, lastname, besttime, companyname, nonprofit, requesteddate, requestedtime, attendance, eventtype, other, leadsource, notes, catering, bar, damagedeposit, dancefloor) 
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    

    Please note that I’ve broken up the line of code for readability. Also, the order you add your parameters to the collection matters. They need to be in the order that matches the columns (The value for eventspecialist must be first, the one for phon second, etc.) It may also be the case that you need to name your parameters the same as the column names, as @shahkalpesh suggests.

    ODBC commands use ? to access parameters, rather than the parameter name as SQL commands do. A couple links on the subject:

    http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx

    http://msdn.microsoft.com/en-us/library/8dcw81x5.aspx

    Edit

    I notice you’re passing all the values to the method as string. You’ll need to convert those to the correct type, and use the correct ODBC data type, when adding parameters. Please see this link for ODBC parameter types.

    Use whatever type the column is (varchar, money, etc), and if your variables (eventspecialist, etc) are not of the correct type, convert the values to the correct type (as indicated in the link) before adding them. For example, cmd.Parameters.Add("@ATTENDANCE", OdbcType.Int).Value = Int32.Parse(attendance);. Please note that Int32.Parse may throw an error if attendance is not a string which represents an integer. I suggest changing the method signature to require the correct types, then validating and converting them before the call to execution. This will avoid type conversion errors in this method. That way, if you do get an error here, you know it’s related to the interaction with the DB, rather than setting up the command incorrectly.

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

Sidebar

Related Questions

I'm making myself a little messenger just for fun. And I want to make
This sounds funny..just a little experiment. i wanted to simulate a drag drop of
So I'm a little new at this, a the code I have so far
I've put together a little script that works fine in general, it just needs
im coding up a HTML form just now and i havinfg a little trouble
Just to play around a little, I'm trying to make a turn-based battle game
I've pretty much convinced myself that this is just leaky abstraction rearing it's ugly
I am playing about just now trying to teach myself a little bit about
I just threw this little mouse tracking example together when I realized, that it
Just a little edit, in case it helps anyone out who happens to stumble

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.