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
Solved

error with sqlparameter array C#  (Visual studio 2.0)

Posted on 2006-11-21
3
930 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript to set controls visibility 5 48
imap read mail 1 34
VB.net Move a class from Solution Items to a project 2 33
asp.net open new page without popup blocker 8 18
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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