日期:2014-05-18  浏览次数:20435 次

什么问题


下面是代码
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq;

public partial class _Default : System.Web.UI.Page
{
    GuestBookDataContext ctx = new GuestBookDataContext("server=.;database=JumbotOA;uid=sa;pwd=sa!#%246");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            SetBind();
        }
    }
    private void SetBind()
    {

        rpt_Message.DataSource = from c in ctx.tbGuestBook orderby c.PostTime ascending select new { c.UserName, c.PostTime, c.Message, c.IsReplied, c.Reply };
        rpt_Message.DataBind();

    }


    protected void btn_SendMessage_Click(object sender, EventArgs e)
    {

        tbGuestBook gb = new tbGuestBook();       
        gb.UserName = tb_UserName.Text;

        gb.Message = tb_Message.Text;

        gb.IsReplied = false;

        gb.PostTime = DateTime.Now;

        ctx.tbGuestBook.Add(gb);

        ctx.SubmitChanges();

        SetBind();






    }
}



------解决方案--------------------
1、tbGuestBook 这个类里边可能没有Add方法,你可以把这个类贴出来看一下
2、如果这个类不是在当前项目里边,那么,你需要在当前项目中添加引用,如同三层一样,需要在当前项目中添加BLL引用,然后再上边的名空间里边添加using引用
------解决方案--------------------
ctx.tbGuestBook.InsertOnSubmit(gb);