条件订单中的问题 [英] problem in Conditional orders

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

问题描述



1-当我删除if()-else()命令时,标签显示ID字段值.但是,当我放置if()-else()命令时,label不显示任何内容.所有检查列的值均为1.
2-条件订单迅速降低.如何优化以下说明

Hi,
Hi,
1- when I delete the if()-else() command, label display id field value. But when I put the if()-else() command, label does not display anything. all check column have value 1.
2- Conditional orders rapidly lowers.How do I optimize the below instructions

i = 0;
while (i < ds.Tables[0].Rows.Count)
{
	if (ds.Tables[0].Rows[i]["check"] == "1")
	{
		int digit = ds.Tables[0].Rows[i]["digit"];
		try
		{
			int div= digit/i;
			Label1.Text += ds.Tables[0].Rows[i]["id"].ToString() + ", ";
			i++;
		}

		catch ()
		{
			string id = ds.Tables[0].Rows[i]["id"].ToString();
			Label1.Text += ds.Tables[0].Rows[i]["id"].ToString() + ", ";
			cmd.CommandText = "update mytb set check=0 where id=" + id + "";
			con.Open();
			cmd.ExecuteNonQuery();
			con.Close();
			i++;
		}
	}

	else
	{
		i++;
	}
}

推荐答案

1)在快速监视中,验证"check"列在任何行中是否具有值"1",
2)您必须按照Sourav Sarkar的建议将代码更改为
if(ds.Tables [0] .Rows [i] ["check"].ToString().Trim()=="1")
1) In quick watch verify whether column "check" has a value "1" in any of the rows,
2) You have to Change your code as suggested by Sourav Sarkar to
if (ds.Tables[0].Rows[i]["check"].ToString().Trim() == "1")


这是因为您的检查列包含0或其他不是1.
这就是为什么要执行i ++命令的原因.

使用Trim()函数
Its because your check column contain 0 or something else not 1.
that''s why its excuting i++ command.
or
Use Trim() function
if (ds.Tables[0].Rows[i]["check"].ToString().Trim() == "1") 


if (Convert.ToInt32(ds.Tables[0].Rows[i]["check"]))== 1)


您好,即使您使用的逻辑没有任何意义,我也已尽可能地重组了代码:S无论如何,您应该学习了很多基本级别的编码东西",例如条件检查,尝试catch块,管理数据库连接,注释,变量命名约定,字符串操作等.

慢慢来,一一慢慢.但要全部学习.

我希望重组对业绩有所帮助.如果您解释了自己真正想做的事,那么可以很轻松地帮助您.

希望能对您有所帮助,
Hi there, I''ve restructured your code as much as possible even though the logic you''ve used, does not make ANY sense :S Anyways, you ought learn so many basic level coding ''stuff'' like condition checking, try catch blocks, managing db connections, commenting, variable naming conventions, string manipulation, etc.

Take it slow and one by one; but learn them all.

I hope the restructuring helps the performance. If you explain what you really want to do, it would make it a lot easier to help you out.

Hope this helps, Regards
int i = 0;

// This condition prevents the logic even starting if there are no valid data
if ((ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
{
	for (int counter = 0; counter < ds.Tables[0].Rows.Count; counter++)
	{
		DataRow currentRow = ds.Tables[0].Rows[counter];

		try
		{
			// I don't know why you've declared these 
			// 'div' & 'digit' variables and logic
			// if you don't use it :S
			int digit = (int) currentRow["digit"];
			int div = digit/i;
		} 
		catch
		{
			// I've not caught the exception to a variable, because you don't use it

			SqlConnection con = new SqlConnection();
			SqlCommand cmd = con.CreateCommand();
			cmd.CommandText = "UPDATE [mytb] SET [check]=0 WHERE [id] = @id";
			cmd.CommandType = CommandType.Text;
			cmd.Parameters.AddWithValue("@id", currentRow["digit"]);

			try
			{
				con.Open();
				cmd.ExecuteNonQuery();
			} 
			catch
			{
				if (con.State != ConnectionState.Closed)
					con.Close();
			}
		}

		Label1.Text += string.Format("{0}, ", currentRow["id"].ToString());
	}
}


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

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