在sql数据源asp.net中设置插入参数的默认值

发布于 2024-11-08 21:09:14 字数 1500 浏览 0 评论 0原文

我有一个数据源,它有一个 insertparameters,其中一个类型设置为布尔值,但是从 insertparameters.defaultvalue 后面的代码添加它时始终返回字符串。

代码背后的代码:

if (e.CommandName == "InsertNew")
{
    TextBox Title = GridView1.FooterRow.FindControl("txtAddTitle") as TextBox;
    TextBox Quote = GridView1.FooterRow.FindControl("txtAddQuote") as TextBox;
    TextBox QuoteLink = GridView1.FooterRow.FindControl("txtAddQuoteLink") as TextBox;
    CheckBox Published = GridView1.FooterRow.FindControl("chkAddBox") as CheckBox;
    TextBox PublishedDate = GridView1.FooterRow.FindControl("txtAddPublishedDate") as TextBox;

    SqlDataSource1.InsertParameters["Title"].DefaultValue = Title.Text;
    SqlDataSource1.InsertParameters["Quote"].DefaultValue = Quote.Text;
    SqlDataSource1.InsertParameters["QuoteLink"].DefaultValue = QuoteLink.Text;
    SqlDataSource1.InsertParameters["Published"].DefaultValue = Convert.ToString(Published.Checked);
    SqlDataSource1.InsertParameters["PublishedDate"].DefaultValue = PublishedDate.Text;
     SqlDataSource1.Insert();
}

sql数据源的aspx代码是:

<InsertParameters>  
    <asp:Parameter Name="Title" Type="String" />  
    <asp:Parameter Name="Quote" Type="String" />  
    <asp:Parameter Name="QuoteLink" Type="String" />  
    <asp:Parameter Name="Published" Type="Boolean" />  
    <asp:Parameter Name="PublishedDate" Type="DateTime" />  
</InsertParameters>

请回复我应该如何从代码后面将数据类型设置为布尔值。

i have a datasource, which has an insertparameters, one of which whose type is set to Boolean, but while adding it from code behind insertparameters.defaultvalue always return string.

code behind code:

if (e.CommandName == "InsertNew")
{
    TextBox Title = GridView1.FooterRow.FindControl("txtAddTitle") as TextBox;
    TextBox Quote = GridView1.FooterRow.FindControl("txtAddQuote") as TextBox;
    TextBox QuoteLink = GridView1.FooterRow.FindControl("txtAddQuoteLink") as TextBox;
    CheckBox Published = GridView1.FooterRow.FindControl("chkAddBox") as CheckBox;
    TextBox PublishedDate = GridView1.FooterRow.FindControl("txtAddPublishedDate") as TextBox;

    SqlDataSource1.InsertParameters["Title"].DefaultValue = Title.Text;
    SqlDataSource1.InsertParameters["Quote"].DefaultValue = Quote.Text;
    SqlDataSource1.InsertParameters["QuoteLink"].DefaultValue = QuoteLink.Text;
    SqlDataSource1.InsertParameters["Published"].DefaultValue = Convert.ToString(Published.Checked);
    SqlDataSource1.InsertParameters["PublishedDate"].DefaultValue = PublishedDate.Text;
     SqlDataSource1.Insert();
}

and aspx code for sql datasource is:

<InsertParameters>  
    <asp:Parameter Name="Title" Type="String" />  
    <asp:Parameter Name="Quote" Type="String" />  
    <asp:Parameter Name="QuoteLink" Type="String" />  
    <asp:Parameter Name="Published" Type="Boolean" />  
    <asp:Parameter Name="PublishedDate" Type="DateTime" />  
</InsertParameters>

Please reply how should i set the datatype as boolean from code behind.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄人书 2024-11-15 21:09:14

1:不确定为什么要设置 DefaultValue 而不是该值

或者

2:您可以尝试以下操作:

SqlDataSource1.InsertParameters["Published"].DefaultValue = Published.Checked==true?"true":"false";

1: Not sure why you are setting DefaultValue instead of the value

Or

2: Can you try this:

SqlDataSource1.InsertParameters["Published"].DefaultValue = Published.Checked==true?"true":"false";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文