0

这是我的标记:

<div class="postit">
    <ul>
        <li>
            <asp:Label ID="lblPostBaslik" runat="server" Text="Baslik :" CssClass="postit-label"></asp:Label>
            <asp:TextBox ID="txtBaslik" runat="server" CssClass="postit-txtbox" ></asp:TextBox>
        </li>
        <li>
            <asp:Label ID="lblPostEtiket" runat="server" Text="Etiket :" CssClass="postit-label"></asp:Label>
            <asp:TextBox ID="txtEtiket" runat="server" CssClass="postit-txtbox" ></asp:TextBox>
            <li class="aciklama">
                <asp:Label ID="lblAciklama" runat="server" Text="Açiklama :" CssClass="postit-label"></asp:Label>
                <asp:TextBox ID="txtAciklama" runat="server" CssClass="postit-txtbox-aciklama"  TextMode="MultiLine" ></asp:TextBox>
            </li>
            <div class="postitbuttons" id="postitbuttons">
                <asp:Button ID="btnKaydet" runat="server" Text="Kaydet"  CssClass="submit button large" onclick="btnKaydet_Click"  />
                <asp:Button ID="btnVazgec" runat="server" Text="Vazgeç" CssClass="submit button large"/>
                <%--<asp:LinkButton ID="btnKaydet" runat="server" CssClass="submit button large"  CommandName="Insert">Kaydet</asp:LinkButton>
                <asp:LinkButton ID="btnKapat" runat="server" CssClass="submit button large" CommandName="Cancel">Vazgeç</asp:LinkButton>--%>
            </div>
        </li>
    </ul>
</div>
<asp:ObjectDataSource ID="ods_postit" runat="server"  DataObjectTypeName="Post" TypeName="yonet" InsertMethod="PostEkle" >
    <InsertParameters>
        <asp:ControlParameter ControlID="txtBaslik" PropertyName="Text" Name="Post_Baslik" Type="String" />
        <asp:ControlParameter ControlID="txtEtiket" PropertyName="Text" Name="Post_Etiket" Type="String" />
        <asp:ControlParameter ControlID="txtEtiket" PropertyName="Text" Name="Post_Icerik" Type="String" />
    </InsertParameters>
</asp:ObjectDataSource> 

当我单击 btnKaydet 时,出现以下错误:

“ObjectDataSource 'ods_postit' 没有要插入的值。检查 'values' 字典是否包含值。”

有什么问题?可以是这样的吗:

<asp:ObjectDataSource ID="ods_postit" runat="server"  DataObjectTypeName="Post" TypeName="yonet" InsertMethod="PostEkle" >

我试图断点,但它不会触发 databaseworks.cs 和 yonet.cs。

我不能使用这个 OOP 代码吗?我不想使用(formview 等)之类的表单。

这是代码隐藏和其他类:

protected void btnKaydet_Click(object sender, EventArgs e)
{
    ods_postit.Insert();
}

Post.cs

public class Post
{
    //Post Private Özellikleri
    private int _post_id;
    private Guid _post_user_id;
    private string _post_baslik;
    private string _post_etiket;
    private string _post_icerik;
    //Post Public Özellikleri
    public int Post_ID
    {
        get { return _post_id; }
        set { _post_id = value; }
    }
    public Guid Post_User_ID
    {
        get { return _post_user_id; }
        set { _post_user_id = value; }
    }
    public string Post_Baslik
    {
        get { return _post_baslik; }
        set { _post_baslik = value; }
    }
    public string Post_Etiket
    {
        get { return _post_etiket; }
        set { _post_etiket = value; }
    }
    public string Post_Icerik
    {
        get { return _post_icerik; }
        set { _post_icerik = value; }
    }
}

数据库工程.cs

public static void PostEkle(Post post)
{  
    using (SqlConnection baglanti = new SqlConnection(dbconnect()))
    {
        SqlCommand komut = new SqlCommand("sp_post_ekle", baglanti);
        komut.CommandType = CommandType.StoredProcedure;
        komut.Parameters.AddWithValue("post_id", post.Post_ID);
        komut.Parameters.AddWithValue("post_user_id",Membership.GetUser().ProviderUserKey);
        komut.Parameters.AddWithValue("post_baslik", post.Post_Baslik);
        komut.Parameters.AddWithValue("post_etiket","#" + post.Post_Etiket);
        komut.Parameters.AddWithValue("post_icerik", post.Post_Icerik);
        baglanti.Open();
        komut.ExecuteNonQuery();
        baglanti.Close();
    }
}

yonet.cs

public static void PostEkle(Post post)
{
    databaseworks.PostEkle(post);
}
4

1 回答 1

1

FormView 或 DetailsView 处理 UI 控件和数据源之间的集成,以及所有与 Bind 语句的绑定,您没有指定(我认为即使您使用 ControlParameter 也很重要;要么那个,要么控件参数将起作用,但您需要 FormView 控件)。

此外,在您的场景中,ODS 不会为您带来任何好处。您可以完全转储 ObjectDataSource,将对象中的数据向上推送到您的业务层并将数据写入您的命令。

于 2013-04-26T14:09:57.203 回答