使用c#在asp.net中添加空字段
本文关键字:添加 字段 net asp 使用 | 更新日期: 2023-09-27 18:12:49
// Add product data to DB.
AddProducts products = new AddProducts();
bool addSuccess = products.AddProduct(AddProductName.Text, AddProductDescription.Text, AddSubHeading1.Text, AddSubInfo1.Text, AddSubHeading2.Text, AddSubInfo2.Text, AddSubHeading3.Text, AddSubInfo3.Text, AddSubHeading4.Text, AddSubInfo4.Text, AddSubHeading5.Text, AddSubInfo5.Text, DropDownAddCategory.SelectedValue, ProductImage.FileName);
if (addSuccess)
{
// Reload the page.
string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
Response.Redirect(pageUrl + "?ProductAction=add");
}
else
{
LabelAddStatus.Text = "Unable to add new product to database.";
}
}
else
{
LabelAddStatus.Text = "Unable to accept file type.";
}
我正在为我的雇主创建一个网站,该网站有一个允许用户添加产品的管理页面,我现在尝试了几种方法,但我无法通过此页进入数据库输入空字段。有人能帮忙吗?
可以检查字符串是否为空,并使用
给出一个' '值AddProductName?.Text?? " " //in C#6.0
或者
if(string.IsNullOrEmpty(AddproductName.Text))
{
AddproductName.Text=" ";
}
,然后尝试插入数据库
如果为null,还要检查数据库是否允许接受空值或null值