Solved

OleDbParameterCollection - Problem with sql statment with string and int

Posted on 2009-05-07
1
1,085 Views
Last Modified: 2012-06-22
Error message: The OleDbParameterCollection only accepts non-null OleDbParameter type objects, not String objects.

se code. The problem I have is the string variable. How should it be done?
public void registreraNyFilm(Filminfo film)

        {

            registreraRegisor(film);

            int regisorId = getRegisor(film.Regissor);

            registreraGenre(film);

            int genreid = getGenre(film.Genre);

            registreraRentCost(film.RentCost);

            int idprice = getRentCost(film.RentCost);            

           

            String myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\Documents and Settings\\MFL\\Dokumenter\\Visual Studio 2008\\Projects\\ProjektFilm\\ProjektFilm\\FemmanFilm_ver1.mdb";
 

            string sql = "INSERT INTO t_movie (title, directorid, genreid, rentcostid) Values(@name, @director, @genre, @rentcost)";

            OleDbConnection cn = new OleDbConnection(myConnectionString);

            using (OleDbCommand cmd = new OleDbCommand(sql, cn))

            {
 

                cmd.Parameters.Add("@rentcost", OleDbType.Integer).Value = idprice;                       

                cmd.Parameters.Add("@genre", OleDbType.Integer).Value = genreid;        

                cmd.Parameters.Add("@director", OleDbType.Integer).Value = regisorId;

                cmd.Parameters.Add("@name"); 

                cn.Open();

                cmd.Parameters[0].Value = idprice;

                cmd.Parameters[1].Value = genreid;

                cmd.Parameters[2].Value = regisorId;

                cmd.Parameters[3].Value = film.Titel;

                cmd.ExecuteNonQuery();

                cn.Close();

            }

        }

Open in new window

0
Comment
Question by:Mickeys
1 Comment
 
LVL 2

Accepted Solution

by:
JulienVan earned 500 total points
ID: 24323313
Can you try to define the type of the parameter as WChar, as in the code below?

You can also define by default Titel = string.Empty when you declare Titel in the FilmInfo class.
cmd.Parameters.Add("@name", OleDbType.WChar);

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now