开发者

Please show me what's going wrong with this delete row function for SQL in C#

I am trying to learn the basics of making databases in Visual C#, and I am building a basic application. In the application there is a delete button that will delete the record that is currently shown in the textboxes. The code I have at the moment is this:

private void btnDelete_Click(object sender, EventArgs e)
{
    currentRow.Delete();
    dAdapter.Update(dataset, "Contacts");
    clearTextBoxes();
}

currentRow is the DataRow I want to delete and that which is shown in the textboxes. dataset is the Dataset. dAdapter is the DataAdapter, and "Contacts" is the table name or w/e. 开发者_Python百科However this is generating an error sometimes. What's wrong here? Thanks!


Have you set the dAdapter.DeleteCommand property? Based on the error message, it sounds like this property might not be set or may be invalid.


You need to outline a delete command, something like this:

<asp:SqlDataSource ID="dAdapter" DeleteCommand="DELETE FROM [Sheep] WHERE Id = @Id">
    <DeleteParameters>
        <asp:Parameter Name="@Id" />
    </DeleteParameters>
</asp:SqlDataSource>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜