如何从数据库中查看特定用户数据?

时间:2017-08-09 11:54:11

标签: javascript c# asp.net ajax repeater

当用户注册数据时,数据已插入数据库,但单个用户将在表单中登录,同时登录数据库中的输入数据已在用户详细信息页面中查看。但我只需要一个用户的特定数据。如果有错误请检查我的代码,所以请提及我。

下面的附加数据库截图

在此屏幕中,

从数据库中拍摄了两个用户保存的信息(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();
                }
            }
        }
    }

1 个答案:

答案 0 :(得分: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