Solved

OleDbParameterCollection - Problem with sql statment with string and int

Posted on 2009-05-07
1
1,083 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

15 Experts available now in Live!

Get 1:1 Help Now