Solved

OleDbParameterCollection - Problem with sql statment with string and int

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

786 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