Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i been trying to save my data into the database but it seem that problem is that the orderID and OrderDate and CustomerID is not suppiled. But i do not know why?
The error keep saying The parameterized query '(@orderId nvarchar(4000),@customerId nvarchar(4000),@orderDate n' expects the parameter '@orderId', which was not supplied.

this us my xml file that i trying to store in the database(using Vs builtin database)
XML
<Order Order_ID="1" Order_Date="1/2/2013" Buyer_ID="GFS1810">
  <Remark />
  <Item Item_ID="123" Size="M" Color="blue" Quantities="10" ePrice="33.77">Very Nice</Item>


my xml code
XML
XmlNodeList nodelist = xmlDoc.GetElementsByTagName("Order");
foreach (XmlNode onode in nodelist)
{
    if (onode.Attributes.Count > 0)
    {
        textBox2.Text = "Order_ID = "+ onode.Attributes[0].Value + Environment.NewLine;
        textBox2.Text += "Order_Date = " + onode.Attributes[2].Value + Environment.NewLine;
        textBox2.Text += "Buyer_ID = " + onode.Attributes[1].Value + Environment.NewLine;
    }
}


XML
XmlNodeList savList = sav.GetElementsByTagName("Order");
            ArrayList sList = new ArrayList();
            Order o = new Order();
            foreach (XmlNode node in savList)
            {
                o = new Order();
                o.orderId = node.Attributes[0].Value;
                o.orderDate = node.Attributes[2].Value;
                o.customerId = node.Attributes[1].Value;
                sList.Add(o);
            }


this is my sql code
C#
string strsql = "insert into [Order] (OrderID, CustomerID, OrderDate)" + "values (@orderId, @customerId,@orderDate);";
public void insertOrder(ArrayList olist)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["Sup_DB_1.Properties.Settings.Sup1ConnectionString"].ConnectionString;
            conn.Open();
            foreach (Order o in olist)
            {
                SqlCommand comm = new SqlCommand(strsql, conn);
                comm.Parameters.AddWithValue("@orderId", o.orderId);
                comm.Parameters.AddWithValue("@customerId", o.customerId);
                comm.Parameters.AddWithValue("@orderDate", o.orderDate);

                comm.ExecuteNonQuery();
            }
            conn.Close();
        }


this is my order class
C#
class Order
    {
        private string OrderId;
        private string OrderDate = "00/00/0000";
        private string CustomerId;
        private string Instructions;

        public string orderId
        {
            get { return OrderId; }
            set { value = OrderId; }
        }

        public string orderDate
        {
            get { return OrderDate; }
            set { value = OrderDate; }
        }

        public string customerId
        {
            get { return CustomerId; }
            set { value = CustomerId; }
        }

        public string instructions
        {
            get { return Instructions; }
            set { Instructions = value; }
        }
 
    }
Posted
Updated 10-Feb-13 19:51pm
v3

1 solution

The variable name used in your query and passed to the SqlParameter are different.
Replace
C#
string strsql = "insert into [Order] (OrderID, CustomerID, OrderDate)" + "values ( orderId, customerId, orderDate);";

with
C#
string strsql = "insert into [Order] (OrderID, CustomerID, OrderDate)" + "values (@orderId, @customerId,@orderDate);";
 
Share this answer
 
Comments
blade Zero 11-Feb-13 1:27am    
i have replace but the same error still appear
Jibesh 11-Feb-13 1:33am    
can you paste the updated code. From the exception its clearly says there miss match with the parameter name passed.
blade Zero 11-Feb-13 1:47am    
have updated the question
Jibesh 11-Feb-13 1:50am    
i dont see any update on the strsql variable value, query preparation statement please update with correct code. looks like you havent modified the code snippet what i typed above.
blade Zero 11-Feb-13 1:51am    
srry tat i misslook now is really updated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900