SqlCommand cmd = new SqlCommand("SELECT * FROM [order] WHERE date>=@begin AND date<=@end", con);
cmd.Parameters.AddWithValue("@begin",dt1);
cmd.Parameters.AddWithValue("@end", dt2);
Run Code Online (Sandbox Code Playgroud)
这是我的选择声明.我想把结果放到数据gridview.如何在asp.net C#中使用数据集存储在gridview中?
我收到一个错误:
已经有一个与此命令关联的打开DataReader,必须先关闭它.
我的代码:
SqlCommand cmd = new SqlCommand("SELECT * FROM shoppingcart", con);
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
found = true;
productdate = Convert.ToDateTime(dr.GetString(4));
string ago1 = string.Format("{0:MM/dd/yy}", Convert.ToString(productdate));
string productdate1 = string.Format("{0:MM/dd/yy}", Convert.ToString(ago));
int productqty = Convert.ToInt32( dr.GetValue(3));
int productID = Convert.ToInt32(dr.GetValue(2));
int cartID = Convert.ToInt32(dr.GetValue(0));
if (productdate < ago)
{
SqlCommand updateproducts = new SqlCommand("UPDATE products SET ProductQuantity=ProductQuantity+@ProductQuantity WHERE ProductID=@ProductID", con);
updateproducts.Parameters.AddWithValue("@ProductQuantity", productqty);
updateproducts.Parameters.AddWithValue("@ProductID", productID);
updateproducts.ExecuteNonQuery();
SqlCommand deletecart = new SqlCommand("DELETE FROM shoppingcart WHERE ID=@ID", …Run Code Online (Sandbox Code Playgroud) 我现在正在使用Windows 8尝试安装wamp服务器,但它有禁止的错误
我试试这个并且不行
AllowOverride none要求全部授予
con.Open();
SqlCommand cmd=new SqlCommand("INSERT INTO user(Firstname,Lastname,Email,Pass,Type)
values(@first,@last,@email,@pass,@type)",con);
cmd.Parameters.Add("@first",SqlDbType.NVarChar).Value = txtfirst.Text;
cmd.Parameters.Add("@last",SqlDbType.NVarChar).Value = txtlast.Text;
cmd.Parameters.Add("@email",SqlDbType.NVarChar).Value = txtemail.Text;
cmd.Parameters.Add("@pass",SqlDbType.NVarChar).Value = txtpass.Text;
cmd.Parameters.Add("@type",SqlDbType.NVarChar).Value = "customer";
cmd.ExecuteNonQuery();
con.Close();
Run Code Online (Sandbox Code Playgroud)
我的语法有什么问题,它说"关键字'user'附近的语法不正确."