2017-08-09 118 views
0

當用戶註冊數據時,數據已被插入到數據庫中,但單個用戶將在表單中登錄,而登錄數據庫中的輸入數據時已在用戶詳細信息頁面中查看。但我只需要一個特定用戶的數據。並檢查我的代碼,以防錯誤,所以請提及我。如何查看數據庫中的特定用戶數據?

下面這個屏幕附加數據庫截圖

拍攝了兩部用戶從數據庫(ID 1ID 10003)保存的信息。如果ID=1用戶登錄需要查看特定用戶的詳細信息,但在這種情況下,如果有任何一個用戶登錄了整個數據庫用戶詳細信息已被顯示。如何糾正這個問題。

DataBase

Error page

<div class="tg-bordertop tg-haslayout"> 
        <div class="tg-formsection tg-experience"> 
         <div class="tg-heading-border tg-small"> 
          <h3>Doctor Social Network</h3> 
         </div> 
         <asp:HiddenField ID="hdnsocial" runat="server" /> 
         <div class="tg-education-detail tg-haslayout"> 
         <asp:Repeater ID="rptsocial" runat="server"> 
           <HeaderTemplate> 
            <div class="table-responsive"> 
           <table class="table-striped educations_wrap table" id="table-striped"> 
           <thead class="cf"> 
            <tr> 
            <th>Facebook</th> 
            <th>Twitter</th> 
            <th>linkedin</th> 
            <th>Pinterest</th> 
            <th>GooglePlusID</th> 
            </tr> 
           </thead> 
             </HeaderTemplate> 
            <ItemTemplate> 
            <tbody class="educations_item"> 
             <tr> 
             <td data-title="FaceBook"><asp:Label ID="lblFaceBookID" runat="server" Text='<%# Eval("FaceBookID") %>' />      
              <div class="tg-table-hover education-action"> 
               <a id='<%#Eval("DoctorSocialID")%>' href="javascript:;" class="delete-me" data-toggle="modal" data-target="#Socialdelete<%#Eval("DoctorSocialID")%>"><i class="tg-delete fa fa-close"></i></a> 
               <a id='<%#Eval("DoctorSocialID")%>' data-toggle="modal" data-target="#Socialedit<%#Eval("DoctorSocialID")%>" href="javascript:;" class="edit-me EditSocial"><i class="tg-edit fa fa-pencil"></i></a> 
              </div> 
              <td data-title="Twitter"><asp:Label ID="lbiTwitterID" runat="server" Text='<%# Eval("TwitterID") %>' /></td> 
              <td data-title="linkedin"><asp:Label ID="lbllinkedinID" runat="server" Text='<%# Eval("linkedinID") %>' /></td> 
              <td data-title="Pinterest"><asp:Label ID="lblPinterestID" runat="server" Text='<%# Eval("PinterestID") %>' /></td> 
              <td data-title="GooglePlus"><asp:Label ID="lblGooglePlusID" runat="server" Text='<%# Eval("GooglePlusID") %>' /></td> 
             </td> 
             </tr> 
             <tr> 
              <td> 
               <div class="modal fade bs-example-modal-lg" id='Socialedit<%#Eval("DoctorSocialID")%>' tabindex="-1" 
               role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="background-color:black;"> 
               <div class="modal-header" style="background-color:white;"> 
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> 
                 ×</button> 
                <h4 id="myModalLabel"> 
                 Edit Social Network</h4> 
               </div> 
               <div class="modal-body" style="background-color:white;"> 
               <div class="errorEditTitle"> 
                </div> 
                <table class="index-table"> 
                 <tr> 
                  <td> 
                   <label> 
                    FaceBook<sub>*</sub></label> 
                  </td> 
                  <td> 
                   <asp:TextBox ID="txtFaceBookID" runat="server" onchange="javascript:EditSocialvalue(this);" Text='<%#Eval("FaceBookID")%>' required class="form-control"></asp:TextBox> 
                  </td> 
                 </tr> 
                 <tr> 
                  <td> 
                   <label> 
                    Twitter<sub>*</sub></label> 
                  </td> 
                  <td> 
                   <asp:TextBox ID="txtTwitterID" runat="server" Class="form-control" onchange="javascript:EditSocialvalue1(this);" required Text='<%#Eval("TwitterID")%>' ></asp:TextBox> 
                  </td> 
                 </tr> 
                 <tr> 
                  <td> 
                   <label> 
                    linkedin<sub>*</sub></label> 
                  </td> 
                  <td> 
                   <asp:TextBox ID="txtlinkedinID" runat="server" Class="form-control" Text='<%#Eval("linkedinID")%>' onchange="javascript:EditSocialvalue2(this);" ></asp:TextBox> 
                  </td> 
                 </tr> 
                 <tr> 
                  <td> 
                   <label> 
                    Pinterest<sub>*</sub></label> 
                  </td> 
                  <td> 
                   <asp:TextBox ID="txtPinterestID" runat="server" Class="form-control" Text='<%#Eval("PinterestID")%>' onchange="javascript:EditSocialvalue3(this);"></asp:TextBox> 
                  </td> 
                 </tr> 
                 <tr> 
                  <td> 
                   <label> 
                    GooglePlus<sub>*</sub></label> 
                  </td> 
                  <td> 
                   <asp:TextBox ID="txtGooglePlusID" runat="server" Class="form-control" Text='<%#Eval("GooglePlusID")%>' onchange="javascript:EditSocialvalue4(this);"></asp:TextBox> 
                  </td> 
                 </tr> 
                 </table> 
                 </div> 
                <div class="modal-footer" style="background-color:white;"> 
                <input type="button" class="btn btn-success" id="btnEditSocial" 
                 value="Update" name="<%#Eval("DoctorSocialID")%>" /> 
                <button class="btn btn-danger" data-dismiss="modal" aria-hidden="true"> 
                 Cancel</button> 
               </div> 
                </div> 
               <!---------------------------------------------------- 
           * Delete HTML Tempaltes 
           ------------------------------------------------- --> 
           <!-- Modal --> 
           <div class="modal fade bs-example-modal-lg" id='Socialdelete<%#Eval("DoctorSocialID")%>' role="dialog"> 
            <div class="modal-dialog modal-sm"> 
             <div class="modal-content" style="width:350px"> 
              <div class="modal-header"> 
               <button type="button" class="close" data-dismiss="modal">&times;</button> 
               <h4 class="modal-title">Delete Confirmation</h4> 
              </div> 
              <div class="modal-body"> 
               <p>Are you sure you want to delete this record?<br /></p> 
              </div><br /> 
              <div class="modal-footer"> 
              <button class="btn button" data-dismiss="modal" aria-hidden="true"> 
               Cancel</button> 
               <input type="button" class="btn btn-danger" id="btnDeleteSocial" 
                 value="Delete" name="<%#Eval("DoctorSocialID")%>" /> 
             </div> 
             </div> 
            </div> 
           </div> 

               </td> 
              </tr> 

            </tbody> 
            </ItemTemplate> 
           <FooterTemplate> 
            </table> 
            </div> 
           </FooterTemplate> 
           </asp:Repeater> 
         </div> 
         <div class="col-sm-12"> 
          <div class="tg-addfield add-new-experiences"> 
           <button type="button" id="AddSocialNetwork"> 
            <i class="fa fa-plus"></i> 
            <span>Add Social Network</span> 
           </button> 
          </div> 
         </div> 
        </div> 
       </div> 



       <!--Start Social --> 
       <div class="tg-bordertop tg-haslayout" id="ShowSocialNetwork" style="display:none;"> 
     <div class="tg-formsection tg-education"> 
      <div class="tg-heading-border tg-small"> 
       <h3>Add Social Network</h3> 
      </div> 
      <div class="tg-education-detail tg-haslayout"> 
       <table class="table-striped educations_wrap" id="table1"> 
       <thead class="cf"> 
        <tr> 
        <th>Facebook</th> 
        <th>Twitter</th> 
        <th>linkedin</th> 
        <th>Pinterest</th> 
         <th>GooglePlusID</th> 
        </tr> 
       </thead> 
        <tbody class="educations_item"> 
         <tr> 
         <td class="education-data edit-me-row" colspan="5"> 
         <div class="education-data-wrap"> 
          <div class="col-md-4 col-sm-6 col-xs-12"> 
           <div class="form-group"> 
            <asp:TextBox ID="txtFaceBookID" runat="server" Class="form-control" placeholder="FaceBook ID"></asp:TextBox> 
           </div> 
          </div> 
          <div class="col-md-4 col-sm-6 col-xs-12"> 
           <div class="form-group"> 
            <asp:TextBox ID="txtTwitterID" runat="server" Class="form-control" placeholder="Twitter ID"></asp:TextBox> 
           </div> 
          </div> 
          <div class="col-md-4 col-sm-6 col-xs-12"> 
           <div class="form-group"> 
            <asp:TextBox ID="txtlinkedinID" runat="server" Class="form-control" placeholder="linkedinID"></asp:TextBox> 
           </div> 
          </div> 
          <div class="col-md-4 col-sm-6 col-xs-12"> 
           <div class="form-group"> 
            <asp:TextBox ID="txtPinterestID" runat="server" Class="form-control" placeholder="Pinterest"></asp:TextBox> 
           </div> 
          </div> 
           <div class="col-md-4 col-sm-6 col-xs-12"> 
           <div class="form-group"> 
            <asp:TextBox ID="txtGooglePlusID" runat="server" Class="form-control" placeholder="GooglePlus"></asp:TextBox> 
           </div> 
          </div> 
          <div class="col-md-4 col-sm-6 col-xs-12"> 
           <div class="form-group"> 
           <input type="button" id="btnSocial" class="btn btn-success" value="Save Social" /> 
           </div> 
           </div> 
          </div> 
         </td> 
         </tr> 
        </tbody> 
        </table> 
      </div> 

     </div> 
    </div> 
       <!--End Socail --> 

保存數據庫功能代碼:

function SaveDocSocial(response) { 
      if (response == null) { 
       callAjax({ 
        url: pageUrl + '/SaveDocSocial', 
        data: '{"Doctorid": "' + $("#<%=hdnDoctorId.ClientID %>").val() + '","DoctorSocialID" : "' + $("#<%=hdnsocial.ClientID %>").val() + '","FaceBookID" : "' + $("#<%=txtFaceBookID.ClientID %>").val() + '","TwitterID" : "' + $("#<%=txtTwitterID.ClientID %>").val() + '","linkedinID" : "' + $("#<%=txtlinkedinID.ClientID %>").val() + '","PinterestID" : "' + $("#<%=txtPinterestID.ClientID %>").val() + '","GooglePlusID" : "' + $("#<%=txtGooglePlusID.ClientID %>").val() + '"}', 
        action: "SaveDocSocial" 
       }); 
       window.location.reload(); 
      } 
      else { 
       loading(false); 
       if (response.AjxContactId != null) { 
        $('#<%=hdnsocial.ClientID%>').val(response.AjxContactId); 
       } 
       msg(true, response.Message); 
      } 
     } 

和頁面加載

this.BindSocial(); 
if (iDoctorID > 0) 

      {hdnsocial.Value = iDoctorID.ToString(); 
} 

節省代碼

[WebMethod] 
    public static UserAjax SaveDocSocial(string Doctorid, string DoctorSocialID, string FaceBookID, string TwitterID, string linkedinID, string PinterestID, string GooglePlusID) 
    { 
     UserAjax oUserAjax = new UserAjax(); 
     string CDoctorID = string.Empty; 
     string DSocialID = string.Empty; 
     int iDoctorID = 0; 
     int iDoctorSocialID = 0; 
     CDoctorID = Doctorid == null ? "" : Doctorid; 
     if (Validation.IsShort(CDoctorID)) 
      iDoctorID = Convert.ToInt32(CDoctorID); 
     DSocialID = DoctorSocialID == null ? "" : DoctorSocialID; 
     if (Validation.IsShort(DSocialID)) 
      iDoctorSocialID = Convert.ToInt32(DSocialID); 
     string sMessage = string.Empty; 
     string sBuild = string.Empty; 
     if (sMessage != "") 
     { 
      oUserAjax.Message = sMessage; 
     } 
     else 
     { 
      BD_Doctor iDoctor = new BD_Doctor(); 
      iDoctor.DoctorID = iDoctorID; 
      iDoctor.DoctorSocialID = iDoctorSocialID; 
      iDoctor.FaceBookID = FaceBookID; 
      iDoctor.TwitterID = TwitterID; 
      iDoctor.linkedinID = linkedinID; 
      iDoctor.PinterestID = PinterestID; 
      iDoctor.GooglePlusID = GooglePlusID; 
      iDoctor.SaveSocial(); 
      //iDoctor.IsDefault = true; 
      if (iDoctorID > 0) 
      { 
       sMessage = "Clinic Information successfully saved!"; 
       oUserAjax.AjxContactId = iDoctorID.ToString(); 
       oUserAjax.Message = sMessage; 
      } 
      else 
      { 
       sMessage = "Your submission failed!"; 
       oUserAjax.Message = sMessage; 
      } 
     } 

     return oUserAjax; 
    } 

查看直放站代碼:

private void BindSocial() 
    { 
     string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; 
     using (SqlConnection con = new SqlConnection(constr)) 
     { 
      using (SqlCommand cmd = new SqlCommand("SELECT * FROM Doctorsocialnetwork", con)) 
      { 
       using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) 
       { 
        DataTable dt = new DataTable(); 
        sda.Fill(dt); 
        rptsocial.DataSource = dt; 
        rptsocial.DataBind(); 
       } 
      } 
     } 
    } 
+0

如果你只是想顯示一個用戶,爲什麼使用一箇中繼器?其次,爲了獲得單個用戶,你的SQL需要一個「WHERE」子句。 – ADyson

+0

ü可以幫助我,先生,請您是這個技術的新成員@ADyson –

+0

好吧,我剛纔說的那一點你不明白?你是ASP.NET新手還是SQL?或兩者? – ADyson

回答

0

是的,我做到了這一點的解決方案

this.BindSocial(hdnsocial.Value); 

用在條件

#region Bind Social 

    private void BindSocial(string hdnsocial) 
    { 
     string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; 
     BD_Doctor iDoctor = new BD_Doctor(); 
     using (SqlConnection con = new SqlConnection(constr)) 
     { 
      using (SqlCommand cmd = new SqlCommand("SELECT * FROM Doctorsocialnetwork where DoctorID = '" + hdnsocial + "'", con)) 
      { 
       using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) 
       { 
        DataTable dt = new DataTable(); 
        sda.Fill(dt); 
        rptsocial.DataSource = dt; 
        rptsocial.DataBind(); 
       } 
      } 
     } 
    } 

    #endregion 
相關問題