0
protected void DetailsView1_ItemInserted(object sender, EventArgs e)
{
    using (SqlCommand cmd2 = new SqlCommand("uspUpdateDisplayHours", cn))
        {
            cn.Open();
            cmd2.CommandType = CommandType.StoredProcedure;
            cmd2.ExecuteNonQuery();
            cn.Close();
        }
        DetailsView1.DataBind();
    }
}

ストアド プロシージャは SQL Server で動作しています - フォーム上の column1 を更新しています。エラーなしで.net上の結果/データを表示しません。

4

3 に答える 3

0

ここで推測しているだけですが、次のようなものはどうでしょうか。

protected void DetailsView1_ItemInserted(object sender, EventArgs e)
{
    DataSet ds = new DataSet();
    using (SqlCommand cmd2 = new SqlCommand("uspUpdateDisplayHours", cn))
    {
        cmd2.CommandType = CommandType.StoredProcedure;
        new SqlDataAdapter(cmd2).Fill(ds);
    }
    DetailsView1.DataSource = ds;
    DetailsView1.DataBind();
    }
}

上記の例では、spから何かを返したいと想定しています。


データベースのデータでDetailsViewを更新するだけの場合(フォームの読み込み時にフォームにデータを入力した場合など)は、そのメソッドを再度実行するだけです。

void PopulateForm() {
    //get data from database and bind it to the ListView
}

protected void DetailsView1_ItemInserted(object sender, EventArgs e)
{ 
    // <= here run the uspUpdateDisplayHours sp

    PopulateForm(); //run this method method again so that the data is refreshed        
} 
于 2009-07-08T17:09:24.187 に答える
0

データベースの挿入、削除、更新の更新に使用するExecuteNonQueryを呼び出しています。

SqlDataReaderオブジェクトに結果を返すExecuteReaderを使用してみてください。

于 2009-07-08T17:11:33.713 に答える
0

ストアド プロシージャが実行されているように見えますが、DataSource を更新する結果を使用していません。実際にデータバインドするには、ストアド プロシージャを実行した後、データベースから何かを取得する必要があります。

データを戻す簡単な例:

protected void DetailsView1_ItemInserted(object sender, EventArgs e)
{
    using (SqlCommand cmd2 = new SqlCommand("uspUpdateDisplayHours", cn))
    using (SqlDataAdapter adapter = new SqlDataAdapter(cmd2))        
        {
            var dataSet = new DataSet();
            cn.Open();
            cmd2.CommandType = CommandType.StoredProcedure;
            adapter.Fill(dataSet);
            var _result = //get to your result some how.
            DetailsView.DataSource = result;
            cn.Close();
        }
        DetailsView1.DataBind();
    }
}

これを行うことは本当にお勧めしません。DetailsView が期待するデータで更新されていないと思う理由を説明するために、これを示しているだけです。

于 2009-07-08T17:03:46.960 に答える