本文介绍了谁能解释?以下代码是如何工作的,逐步解释....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以逐步解释以下代码:


编码:


can anyone explain following code how it works step by step:


Coding:


if (con.State == ConnectionState.Closed)
       {
           con.Open();
       }
       SqlCommand sql = new SqlCommand("select * from category where category_name=''" + txtcategory_name.Text + "''", con);
       if (Convert.ToInt32(sql.ExecuteScalar()) == 0)
       {
           SqlCommand cmd = new SqlCommand("insert into category values(''" + txtcategory_name.Text + "'',''" + txtdescription.Text + "'')", con);
           cmd.ExecuteNonQuery();
           lblmsg.Text = "Submitted";
           con.Close();
       }
       else
       {
           lblmsg.Text = "category Name Already Exists";
       }

推荐答案



if (con.State == ConnectionState.Closed)
{
con.Open();
}



2)检查类别名称是否为txtcategory_name.Category表中是否存在文本名称



2) Check that category_name with txtcategory_name.Text name is exists in Category table

SqlCommand sql = new SqlCommand("select * from category where category_name='" + txtcategory_name.Text + "'", con);
        if (Convert.ToInt32(sql.ExecuteScalar()) == 0)
        {
          ....Code
        }
        else
        {
            lblmsg.Text = "category Name Already Exists";
        }


3)如果没有,则插入类别并通过con.close()关闭连接


3) if not then Insert Category and close Connection by con.close()

SqlCommand cmd = new SqlCommand("insert into category values('" + txtcategory_name.Text + "','" + txtdescription.Text + "')", con);
            cmd.ExecuteNonQuery();
            lblmsg.Text = "Submitted";
            con.Close();


这篇关于谁能解释?以下代码是如何工作的,逐步解释....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 16:20