This doesn't work. I've got an exception from SQL databse that column does not allow nulls.
<asp:SqlDataSource ID="MyDataSOurcet" runat="server"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
InsertCommand="INSERT INTO MyTable(Name) VALUES (@Name) WHERE NameID = 1"
<InsertParameters>
<asp:Parameter Name="Name" Type="String" DefaultValue=""/>
</InsertParameters>
</asp:SqlDataSource>
You could try
<asp:Parameter Name="Name" Type="string" DefaultValue=""
ConvertEmptyStringToNull="false" />
But I thought that was default.
try this:
<asp:SqlDataSource ID="MyDataSOurcet" runat="server" OnInserting="MyDataSOurcetInserting" ... >
//cs
protected void MyDataSOurcetInserting(object sender, SqlDataSourceCommandEventArgs e)
{
//check if nothing has been inserted then
e.Command.Parameters["Name"].value = DBNull.Value;
}
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With