2016-07-16 1 views
0

私は14個のラジオボタンリストを持っています。つまり、クラスルーム、ラボ、スポーツ施設などの各施設を指しています。私は別のデータそれぞれのラジオボタンリストに対して2列の第1列のファシリティおよび第2列を有するデータベースは、各ファシリティのランクすなわち優秀、非常に良い、良好および平均を含む。各ラジオボタンリストのエントリをデータベースに入れるためのコード

<div class="panel-body"> 
<div class="row"> 
    <div class="col-md-6"> 
     <div class="form-group"> 
      <label style="font-size: large">1.Classrooms</label> 
     <asp:RadioButtonList ID="rbclassrooms" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">2.Laboratories </label> 
     <asp:RadioButtonList ID="dblab" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">3.Central Library </label> 
     <asp:RadioButtonList ID="rbcentrallib" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">4. Cleanliness </label> 
     <asp:RadioButtonList ID="rbclean" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">5. Central Computing Center </label> 
     <asp:RadioButtonList ID="rbccc" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">6. Wi-Fi Facility </label> 
     <asp:RadioButtonList ID="rbwifi" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">7. Hostel Facilities </label> 
     <asp:RadioButtonList ID="rbhostel" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">8. Sport Facility </label> 
     <asp:RadioButtonList ID="rbsport" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">9. College Bus Transport </label> 
     <asp:RadioButtonList ID="rbcolgbus" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">10. Canteen Facility</label> 
     <asp:RadioButtonList ID="rbcanteen" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">11. ATM Facility </label> 
     <asp:RadioButtonList ID="rbatm" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">12. Counseling and Health Care </label> 
     <asp:RadioButtonList ID="rbcounselingandhealth" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">13. Washroom and drinking water </label> 
     <asp:RadioButtonList ID="rbwashroom" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 
     <div class="form-group"> 
      <label style="font-size: large">14. Overall Facilities </label> 
     <asp:RadioButtonList ID="rboverall" runat="server" RepeatDirection="Horizontal" CellSpacing="10"> 
      <asp:ListItem style="margin-right:50px">Excellent 
      <asp:ListItem style="margin-right:50px">Very Good 
      <asp:ListItem style="margin-right:50px">Good 
      <asp:ListItem style="margin-right:50px">Average 

      </div> 

    </div> 
+0

4つの異なるクエリ(各施設/平均の1つ)はどうなりますか? – Sami

答えて

0

いくつかのオプション

1)オープン接続上で維持し、複数のINSERT文を実行するには、

using (SqlConnection connection = new SqlConnection(connectionString)) 
{ 
    connection.Open(); 
    using (SqlCommand cmdClassroom= new SqlCommand("insert into YourTable(Facility,Rank)Values(@facility,@rank)", connection)) 
    { 
     cmdClassroom.Parameters.AddWithValue(@facility,"Classroom"); 
     cmdClassroom.Parameters.AddWithValue(@rank,rbclassrooms.SelectedValue); 
    } 
//Similarly for next facilities 
    using (SqlCommand command2 = new SqlCommand(commandText2, connection)) 
    { 
    } 
    // etc 
} 

2)は、各クエリにこのことができます

using (SqlConnection connection = new SqlConnection(connectionString)) 
{ 
    connection.Open(); 
command.CommandText = @" 
insert into YourTable (facility,rank) values ('classroom',@classroomRank); 
insert into YourTable (facility,rank) values ('labs',@labsRank); 
insert into YourTable (facility,rank) values ('lib',@libRank); 
insert into YourTable (facility,rank) values ('Cleanliness',@cleanlinessRank); 

command.Connection = connection; 
command.ExecuteNonQuery(); 
} 

希望をセミコロンを入れて好き!

関連する問題