如何一一更新列值 [英] How to update column value one by one

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

问题描述

大家好

下面是我的代码,用于从数据库中打印行

Hi all

Below is my code for printing rows from database

for (int i = 0; i < j; i++)
                {

                    npgcommand3 = new NpgsqlCommand("Select count(*) from tbl_trans where printed=1", npgconn);
                    npgDA3 = new NpgsqlDataAdapter(npgcommand3);
                    int m = Convert.ToInt32(npgcommand3.ExecuteScalar());

                    if (m >= 30)
                    {
                        MessageBox.Show("Turn the page");
                    }

                    string per = dt.Rows[i][2].ToString();
                    int l = per.Length;
                    }
                    npgcommand2 = new NpgsqlCommand("update tbl_trans set printed=1", npgconn);
                    npgcommand2.ExecuteNonQuery();
                }

                sr.Close();
                //MessageBox.Show("Text Is Written To The File");
                Process ExternalProcess = new Process();
                ExternalProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                ExternalProcess.StartInfo.FileName = "NOTEPAD";
                ExternalProcess.StartInfo.Arguments = " /P D:\\Display.txt";

                ExternalProcess.Start();

                npgconn.Close();


                npgconn.Close();

            }
            catch (Exception e)
            {
                sr.Flush();
                sr.Close();
                MessageBox.Show("Error" + e.Message.ToString());
            }
        }



现在,在此请告诉我如何编写更新查询,通过该查询我可以一个接一个地更新列值.

这是我的表值,我想更新最后一列的值



Now in this please tell me how to write the update query by which i can update column value one by one.

this is my table value and i want to update the last column value

accno      Date        particular    a1      a2    id  cheq  a3     status
123456;"2014-04-03";"ATM W/D CASH";5000.00;5000.00;25;10014;7000.00;1
123456;"2014-04-03";"ATM W/D CASH";5000.00;5000.00;26;10015;7000.00;1
123456;"2014-04-03";"ATM W/D CASH";5000.00;5000.00;27;10016;7000.00;1


我在数据表中有此数据.
我想一张一张地打印一行,并更新一张一张的状态.


i have this data in a datatable..
i want to print row(s) one by one and update the status=0 for each one by one.

推荐答案

如果发出诸如
If you issue a command such as
UPDATE myTable SET column=value

然后它将始终将每一行设置为相同的值:您必须明确说出要更改的列以防止发生这种情况.为此,您可以使用WHERE子句:

Then it will always set every row to the same value: you have to explicitly say which columns you want to change to prevent this. For that you use a WHERE clause:

UPDATE myTable SET column=value WHERE otherColumn=othervalue



我不能帮您编写WHERE子句,因为您的代码没有显示任何相关信息-例如使这些行唯一的列,甚至根本没有检索任何行!



I can''t help you write the WHERE clause, because your code doesn''t show any relevant information - such as the column which makes these rows unique, or even you retrieving any rows at all!


这篇关于如何一一更新列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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