数据未提供?更新为正在编辑的字符串str [英] Data not supplied? updated with string str being edited
问题描述
您好我一直在尝试将我的数据保存到数据库中,但似乎问题是orderID和OrderDate以及CustomerID未被提供。但我不知道为什么?
错误一直说参数化查询''(@ orderId nvarchar(4000),@ customerId nvarchar(4000),@ orderDate n''需要参数''@ orderId'',这不是提供。
这个我的xml文件,我试图存储在数据库中(使用Vs内置数据库)
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)
<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>
我的xml代码
my xml code
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;
}
}
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);
}
这是我的sql代码
this is my sql code
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
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; }
}
}
推荐答案
查询中使用的变量名称并传递给SqlParameter是不同的。
替换
The variable name used in your query and passed to the SqlParameter are different.
Replace
string strsql = "insert into [Order] (OrderID, CustomerID, OrderDate)" + "values ( orderId, customerId, orderDate);";
with
with
string strsql = "insert into [Order] (OrderID, CustomerID, OrderDate)" + "values (@orderId, @customerId,@orderDate);";
这篇关于数据未提供?更新为正在编辑的字符串str的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!