表中的空行 [英] empty rows in the table

查看:101
本文介绍了表中的空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

am使用此代码从表单向表中插入多行,并且可以正常工作.但是当表单的一部分为空时,它将在孔行中插入空白.我怎样才能防止这种情况

表单后面的代码

am using this code to insert multiple rows into a table from a form and it works alright. but when part of the form is empty, it inserts empty space in the hole row. how can i prevent this

code behind form

try
{
    if (string.IsNullOrEmpty(txtActivity1.Text))
    {
        MessageBox.Show("Type Your First Activity");
        return;
    }
    clsCategory person = new clsCategory();
    
    var  _with1 = person;
    _with1.oneCategory = this.txtCategory1.Text;
    _with1.twoCategory = this.txtCategory2.Text;
    _with1.threeCategory = this.txtCategory3.Text;
    _with1.fourCategory = this.txtCategory4.Text;
    _with1.fiveCategory = this.txtCategory5.Text;
    _with1.oneActivity = this.txtActivity1.Text;
    _with1.twoActivity = this.txtActivity2.Text;
    _with1.threeActivity = this.txtActivity3.Text;
    _with1.fourActivity = this.txtActivity4.Text;
    _with1.fiveActivity = this.txtActivity5.Text;
    _with1.saveRegister();
    clearScreen();
    MessageBox.Show("Record is successfully Added");
    
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

推荐答案

我注意到有几件事是这里的问题.首先,要解决您的问题,在决定填充行之前,应首先检查以确保文本字段具有值.除非所有五个字段中都有值,否则请勿触发_with1.saveRegister();行.

接下来,您应该先对字段进行验证,然后再将其直接保存到数据库中.在运行保存"方法之前,请检查以确保字段中的文本有效(没有特殊字符等).否则,您可能会受到SQL注入攻击.
There are a couple things I notice that are issues here. First, to solve your issue, you should first check to be sure the text fields have values before you decide to populate the row. Don''t fire the _with1.saveRegister(); line unless all five fields have values in them.

Next, you should be doing validation on your fields before you save them directly into your database. Before the "Save" method is run, check to be sure the text in the fields is valid (no special characters, etc.) If you don''t, you could be subject to a SQL injection attack.


这篇关于表中的空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆