0

ステータスに基づいて select ステートメントを使用していくつかのレコードを取得する Web サービスを開発しており、ステータスを変更する必要があります。

そのような:

select * from tblx where status='x'

その後

update tblx set status='y' where status='x'取得したレコードについて。

サンプルコード:

 string getpaid = "select top2 * from tblfameface where img_f_p='paid'";
                con1 = new SqlConnection(conString1);
                con1.Open();
                SqlCommand cmd = new SqlCommand(getpaid, con1);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt1 = new DataTable();
                da.Fill(dt1);

                foreach (DataRow row in dt1.Rows)
                {
                    string updatepaid = "update tblfameface set img_f_p='free' where img_f_p='paid' ";
                    con1 = new SqlConnection(conString1);
                    con1.Open();
                    SqlCommand cmd1 = new SqlCommand(updatepaid, con1);
                    int temp = cmd1.ExecuteNonQuery();
                    con1.Close();
                }
}

解決方法がわかりません。

助けてもらえますか??

4

5 に答える 5

1

「更新」クエリを除いて、プロトタイプは問題ありません。更新クエリを次のように書き換えます

update tblx set status='y' where status=(select status from tblx where status='x');

あなたの要件に従って:

string updatepaid = "update tblfameface set img_f_p='free' where img_f_p=(select top 2 img_f_p from tblfameface where img_f_p='paid')";
con1 = new SqlConnection(conString1);
con1.Open();
SqlCommand cmd1 = new SqlCommand(updatepaid, con1);
int temp = cmd1.ExecuteNonQuery();
con1.Close();

うまくいくことを願っています。

于 2013-04-24T11:23:40.387 に答える
0

ここでは、以下のように update ステートメントを 1 つだけ実行できます。

UPDATE YourTable
SET status='Y'
WHERE status='X'
于 2013-04-24T11:22:05.457 に答える
0

もっと具体的にお願いします。SQL または C# に問題がありますか?

これは C# の場合に役立ちます。

http://msdn.microsoft.com/en-us/library/tyy0sz6b.aspx

これはSQLの場合:

http://www.w3schools.com/sql/sql_update.asp

于 2013-04-24T11:22:58.993 に答える
0

ここであなたの更新ステートメントは間違っています:

UPDATE <TABLE NAME> SET <Column> = <New Value> WHERE <Condition>
于 2013-04-24T11:17:47.970 に答える
-1

update tblx set status='y' where status='x';

于 2013-04-24T11:16:02.117 に答える