我有一个带有 2 个字段属性、值并包含 3 个文本框的网格视图。当我输入值时,我将一些文本框保留为空,我需要检查空文本框。并且那些空值不想插入数据库。我怎么解决这个问题???
这是我的代码
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)
{
}
}