Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

error with sqlparameter array C#  (Visual studio 2.0)

Posted on 2006-11-21
3
Medium Priority
?
939 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 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