2016-07-16 57 views
0

我有一个14单选按钮列表每个表示设施为学院即教室,实验室和体育设施等,我需要一个代码,这有助于我插入一个单独的数据对于每个单选按钮列表。具有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个不同的查询(每个设施/平均一个)怎么办? – Sami

回答

0

一些选项

1)保持在连接打开,并执行多重插入语句喜欢

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(); 
} 

希望这有助于!

相关问题