[英]Adding empty fields in asp.net using c#
// 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.";
}
I am creating a website for my employer that has an admin page that allows the user to add products, I have tried a few methods now but I have not been able to enter empty fields into the database through this page. 我正在为我的雇主创建一个网站,其中有一个允许用户添加产品的管理页面,我现在尝试了一些方法,但是我无法通过此页面将空字段输入数据库。 Can anyone help? 有人可以帮忙吗?
Can check whether the string is null and give a ' ' value using 可以检查字符串是否为null并使用给出''值
AddProductName?.Text?? " " //in C#6.0
or you can use 或者你可以使用
if(string.IsNullOrEmpty(AddproductName.Text))
{
AddproductName.Text=" ";
}
and then try inserting into the database 然后尝试插入数据库
if it is null, also check if the database is allowed to take empty or null values. 如果为null,还要检查是否允许数据库采用空值或空值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.