C# 如何根据选择的单选按钮选择不同的数据库行

C# 如何根据选择的单选按钮选择不同的数据库行,c#,asp.net,visual-studio,C#,Asp.net,Visual Studio,我目前正在做一个银行项目,我可以选择我想要查看的交易历史的月份,例如:当前月份,当前月份n上一个月现在,我只能使用grid view检索我拥有的所有交易历史。我可以知道如何根据选择的单选按钮查看不同时期的交易吗?我目前正在使用asp.net n C myConnection.ConnectionString = strConnectionString; SqlCommand cmd = new SqlCommand("SELECT thDate, thType, thAmountIn

我目前正在做一个银行项目,我可以选择我想要查看的交易历史的月份,例如:当前月份,当前月份n上一个月现在,我只能使用grid view检索我拥有的所有交易历史。我可以知道如何根据选择的单选按钮查看不同时期的交易吗?我目前正在使用asp.net n C

  myConnection.ConnectionString = strConnectionString;
    SqlCommand cmd = new SqlCommand("SELECT thDate, thType, thAmountIn, thAmountOut from [Transaction]", myConnection);

    myConnection.Open();

    SqlDataReader reader1 = cmd.ExecuteReader();

    GridView1.DataSource = reader1;
    GridView1.DataBind();

对于SQL命令,您可以尝试:

SqlCommand cmd = new SqlCommand("SELECT thDate, thType, thAmountIn, thAmountOut from [Transaction] where thDate=" + RadioButtonList1.Text + ", myConnection);

其中RadioButtonList1由RadioButtonList的名称替换。这会将所选单选按钮的值放入SQL语句。

没有人知道单选按钮的值是什么样子的。但您可以在查询中使用WHERE子句。选择从…起其中,日期介于'2012/01/01'和'2012/07/01'之间,您需要在此之前创建SqlConnection。@n尽管我知道,但我正在处理提供的信息,从声音上看,连接已经建立,因为他们已经能够检索所有详细信息,并且他们希望得到帮助以缩小搜索范围