0

私は .NET の初心者であり、ラジオ ボタン インデックスで SQL 接続を使用するのが困難で、page_load で定義したイベント ハンドラが変更されました。

以下は私のコードです

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace Controls
{
    public partial class Report_Selection : System.Web.UI.Page
    {


        protected void Page_Load(object sender, EventArgs e)
        {

            GridView1.HeaderStyle.Font.Bold = true;
            RadioButtonList1.SelectedIndexChanged += new EventHandler(RadioButtonList1_SelectedIndexChanged);
using (SqlConnection cnn = new SqlConnection("Data Source=DBSW9079;Initial Catalog=Underwriting;Integrated Security=SSPI;"))

            {
              SqlCommand cmd;
               SqlDataReader sdr;

               if (!IsPostBack)
               {
                   cmd = new SqlCommand("select Categoryid,CategoryTitle  from Report_Category", cnn);
                   cnn.Open();
                   sdr = cmd.ExecuteReader();
                   SelectCategorydlist1.DataSource = sdr;
                   SelectCategorydlist1.DataTextField = "CategoryTitle";
                   SelectCategorydlist1.DataValueField = "categoryid";
                   SelectCategorydlist1.DataBind();
                   cnn.Close();

               }
               else
               {
                   //It's a Post back
                   //make the grid visible and fill it

                   GridView1.Visible = true;
                   RadioButtonList1.SelectedValue = "1";
                   cmd = new SqlCommand("Select rptdesc,rptdesctext,categoryid from report_description " + "where categoryid != 99999"
                       + "and categoryid = " + Convert.ToInt32(SelectCategorydlist1.SelectedValue).ToString(), cnn);
                   cnn.Open();
                   sdr = cmd.ExecuteReader();
                   GridView1.DataSource = sdr;
                   GridView1.DataBind();

                   sdr.Close();





                   {


                   }

               }






                }

            }

        void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {



            SqlCommand cmd1;
            SqlDataReader sdr1;
            if (RadioButtonList1.SelectedIndex.Equals(1))
            {
                RadioButtonList1.ClearSelection();
                cmd1 = new SqlCommand("Select rptdesc,rptdesctext,categoryid from report_description "
                       + "and categoryid = " + Convert.ToInt32(SelectCategorydlist1.SelectedValue).ToString(), cnn);
                cnn.Open();
                sdr1= cmd1.ExecuteReader();
                GridView1.DataSource = sdr1;
                GridView1.DataBind();

                sdr1.Close();
            }

        }







        }
    }

上記のコードで、イベント ハンドラーで cnn の続編接続を使用すると、小さな r が返されます

4

1 に答える 1

0

でのクエリRadioButtonList1_SelectedIndexChangedが正しくないようです。のandないがありwhereます:

Select rptdesc,rptdesctext,categoryid from report_description
and categoryid = ...
^^^ should be WHERE
于 2012-06-05T16:43:49.510 に答える