Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在sql数据源asp.net中设置插入参数的默认值_Asp.net_Sqldatasource - Fatal编程技术网

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

在sql数据源asp.net中设置插入参数的默认值,asp.net,sqldatasource,Asp.net,Sqldatasource,我有一个datasource,它有一个insertparameters,其中一个类型被设置为Boolean,但是当从insertparameters.defaultvalue后面的代码添加它时,它总是返回字符串 代码隐藏代码: if (e.CommandName == "InsertNew") { TextBox Title = GridView1.FooterRow.FindControl("txtAddTitle") as TextBox; TextBox Quote = G

我有一个datasource,它有一个insertparameters,其中一个类型被设置为Boolean,但是当从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>


请回答如何从代码隐藏中将数据类型设置为布尔值。

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

2:你能试试这个吗:

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