Question

Here is my markup:

<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> 

When I clicked btnKaydet, I get the following error:

"ObjectDataSource 'ods_postit' has no values to insert. Check that the 'values' dictionary contains values."

What's the problem? Can it be about this:

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

I tried to breakpoint, but it doesn't fire databaseworks.cs and yonet.cs.

Cant I use this OOP code? I don't want to use forms like (formview, etc).

Here is the code-behind and other classes:

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; }
    }
}

databaseworks.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);
}
Was it helpful?

Solution

The FormView or DetailsView handle the integration between the UI controls and the datasource, and all of the bindings with the Bind statement, which you don't have specified (I think that matters even though you are using ControlParameter; either that, or the control parameters will work but you need the FormView control).

Also, the ODS doesn't gain you anything here in your scenario; you could dump the ObjectDataSource completely, push the data up in an object to your business layer and write the data to your command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top