Solved

error with sqlparameter array C#  (Visual studio 2.0)

Posted on 2006-11-21
3
918 Views
Last Modified: 2010-08-05
I have this function and on the line

SqlParameter[3] smyparams;

I keep getting ";expected" error. I am not sure if this is the right
way to declare a sqlparameter array.

Pls assist.



public  int myInsert(Customer c)
    {
        string sql;
        sql = "insert into customers(customerid,companyname,contactname,country) values(@custid,@company,@contact,@country)";
        SqlParameter[3] smyparams;
       
        smyparams[0] = new SqlParameter("@custid", c.CustomerID);
        smyparams[1] = new SqlParameter("@company", c.CompanyName);
        smyparams[2] = new SqlParameter("@contact", c.ContactName);
        smyparams[3] = new SqlParameter("@country", c.Country);

        SqlHelper sh = new SqlHelper();
        return sh.ExecuteNonQuery(sql, myparams);
        //return SqlHelper.ExecuteNonQuery(sql, myparams);
       
    }
0
Comment
Question by:Sirdots
3 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
ID: 17989884
Try changing

SqlParameter[3] smyparams;
to
SqlParameter[] smyparams = new SqlParameter[4];
0
 
LVL 28

Expert Comment

by:strickdd
ID: 17989943
You could try using a command object, something like this:

string SQL = "insert into customers(customerid,companyname,contactname,country) values(@custid,@company,@contact,@country)";
SqlConnection Connection = new SqlConnection(ConnectionStrings["ConString"]));
            SqlCommand Command = new SqlCommand(SQL, Connection);
            Command.CommandType = CommandType.Text;

            Command.Parameters.AddWithValue("@custid", c.CustomerID);
            Command.Parameters.AddWithValue("@company", c.CompanyName);
            Command.Parameters.AddWithValue("@contact", c.ContactName);
            Command.Parameters.AddWithValue("@country", c.Country);

            Connection.Open();

            Command.ExecuteNonQuery();

            Connection.Close();
0
 

Author Comment

by:Sirdots
ID: 17989949

Thanks Nightman. This works.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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