为啥这个片段不起作用?断开的模型没有被实施

Posted

技术标签:

【中文标题】为啥这个片段不起作用?断开的模型没有被实施【英文标题】:why is this snippet not working? the disconnected model is not being implemented为什么这个片段不起作用?断开的模型没有被实施 【发布时间】:2016-10-07 16:35:53 【问题描述】:
public void make_new_order(IorderBO order)

    int id;
    using (SqlConnection con = DButility.getconnection())
    
        con.Open();
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.CommandType = CommandType.StoredProcedure;
        com.CommandText = "placeorder";
        com.Parameters.AddWithValue("@Customer_name", order.Customer_name);
        com.Parameters.AddWithValue("@Email_id", order.Email_id);
        com.Parameters.AddWithValue("@Phone_number", order.Phone_number);
        com.Parameters.AddWithValue("@Required_quantity", order.Required_quantity);
        com.Parameters.AddWithValue("@Product_id", order.Product_id);
        int row_affected = com.ExecuteNonQuery();
        if(row_affected>0)
        
            HttpContext.Current.Response.Write("<script>alert('Order placed Sucessfully!!')</script>");
            string s = "select max(Order_id) from manchester";
            SqlCommand c = new SqlCommand(s, con);
            id = (int)c.ExecuteScalar();
            HttpContext.Current.Response.Write("<script>alert('Please note your Order-Id:" + id + "')</script>");
        
        con.Close();
    


public List<IorderBO> view_all_order()

    using(SqlConnection con = DButility.getconnection())
    
        List<IorderBO> list_of_order = new List<IorderBO>();
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        con.Open();
        com.CommandType = CommandType.StoredProcedure;
        com.CommandText = "see";
        SqlDataReader r = com.ExecuteReader();
        while(r.Read())
        
            int id = Convert.ToInt16(r["Order_id"].ToString());
            int pid = Convert.ToInt16(r["Product_id"].ToString());
            int re = Convert.ToInt16(r["Required_quantity"].ToString());
            string n = r["Customer_name"].ToString();
            string e = r["Email_id"].ToString();
            Int64 p = Convert.ToInt64(r["Phone_number"].ToString());
            IorderBO or = new orderBO(id, pid, re, n, e, p);
            list_of_order.Add(or);
        
        con.Close();
        return list_of_order;
    


public DataTable searchby_id(int id)

    using (SqlConnection con = DButility.getconnection())
    
        con.Open();
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.CommandType = CommandType.StoredProcedure;
        com.CommandText = "seestat";
        com.Parameters.AddWithValue("@Product_id", id);
        DataTable d = new DataTable();
        SqlDataReader r = com.ExecuteReader();
        d.Load(r);
        return d;
        //con.Close();
           

即使是网格视图事件也不起作用

protected void Page_Load(object sender, EventArgs e)

    List<IorderBO> list_order = new List<IorderBO>();
    list_order = o.view_all_order();
    GridView1.DataSource = list_order;
    GridView1.DataBind();

【问题讨论】:

【参考方案1】:
create procedure placeorder
(@Product_id int ,
@Required_quantity int ,
@Customer_name varchar(50),
@Email_id varchar(30),
@Phone_number bigint)
as
begin
insert into manchester values(@Product_id,@Required_quantity,@Customer_name,@Email_id,@Phone_number)
end
create procedure see
as
begin 
select * from manchester
end
exec see
declare  @Product_id int

create procedure seestat(@Product_id int)
as
begin  
select count(Product_id) As Number_of_Orders from manchester where (Product_id=@Product_id)
end

【讨论】:

以上是关于为啥这个片段不起作用?断开的模型没有被实施的主要内容,如果未能解决你的问题,请参考以下文章

为啥 livewire 数据绑定不起作用?

为啥代码版本控制器在 erlang 中不起作用?

为啥软键盘在对话框片段内的 Web 视图中不起作用?

为啥 saveStateInstance 在屏幕方向上不起作用?

片段中的按钮在android中不起作用

按钮在片段中不起作用