我有一个gridview有2个字段的属性,值和包含3个文本框。 当我输入值时,我将一些文本框保留为空,我需要检查空的文本框。并且空值不想插入到数据库中。我怎么解决这个问题???如何检查在asp.net中的文本框的空白?
这是我的代码
foreach (GridViewRow gvr in GridView1.Rows)
{
string strcon1;
strcon1 = ConfigurationManager.ConnectionStrings["fwma_devConnectionString"].ConnectionString;
SqlConnection con1 = new SqlConnection(strcon1);
con1.Open();
SqlCommand com3 = new SqlCommand(strcon);
TextBox tb = (TextBox)gvr.FindControl("TextBox2");//value
string txt = tb.Text;
Label propertylabel = (Label)gvr.FindControl("Label4");//id-property
com3.CommandText = "INSERT INTO BrandProperties(PropertyID,BrandID,[Values]) values('" + propertylabel.Text + "','" + B_id.Text + "','" + tb.Text + "')";
com3.Connection = con1;
com3.ExecuteNonQuery();
con1.Close();
if (tb.Text == String.Empty)
{
}
}
你需要表现出一定的警告时,这是空的?或者放弃插入? – Fals
只是想放弃那个空的文本框插入。不想显示任何警告。 –
尝试在插入查询之前检查“null”或“Empty”,而不是在“插入”查询之后检查。 – Rahul