الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مالفرق

بدأه الحكيمة في 28 مايو 2011 · 8 رد · 514 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

ماالفرق لمان اكتب في الكود

SQLCommand

or

SQLAdapter

or

SQLDataset

or

SQLReader

يعني انا في اكوادي جربتها كلها بس ماني عارفه اش فايدتها

وكمان اش فايده

IS NotIsPostBack

في البيج لود

واش عمل

ExecuteNonQuery

ياريت احد يشرح لي

ولكم جزيل الشكر

تم تعديل هذه المشاركة بواسطة الحكيمة في 28 مايو 2011 في 22:33

#2

السلام عليكم ورحمه الله وبركاته

اختي بالنسبه ل SqlCommand هو فئة تمثل امر ال SQL المراد تنفيذه, اما ال SqlDataAdapter يمثل الوسيط بين قاعدة البيانات و ال DataSet وليس SqlDataSet والي هي كائن يخزن فيه بيانات من قاعدة البيانات ليوفر النهج المنفصل Connectionless علشان مش كل مره نروح قاعدة البيانات لجلب البيانات اما ال SqlReader فهو قارىء المعلومات وهو كائن يقوم بقراءة البيانات الاتيه من قاعدة البيانات ويستخدم في الوضع المتصل Connection Oriented, واخيرا ال ExecuteNonQuery هي عباره عن طريقه او داله تقوم بتنفيذ امر غير الاستعلام مثل الاضافه والحذف والتعديل ووو

اما IsPostBack فهي خاصيه تبع الكائن Page وترجع قيمه منطقيه true او false وتدل بان الصفحه ارجعت من الخادم وبصوره افتراضيه قيمتها false لأن الصفحه لم تعالج من قبل او تذهب للخادم

.:: Wish to become better and better ::.

#3

طيب اخوي بالنسبه للCType اش هي

وكمان سؤال في الكود الاتي

Protected Sub SqlDataSource2_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource2.Updating
        Dim memIdLabel As Label = CType(DetailsView1.FindControl("lblMember"), Label)
        e.Command.Parameters.Clear()
        Dim memIdParam As SqlParameter = New SqlParameter("@MemberID", SqlDbType.Int)
        memIdParam.Direction = ParameterDirection.Input
        memIdParam.Value = Convert.ToInt32(memIdLabel.Text.Trim())

        e.Command.Parameters.Add(memIdParam)

    End Sub

معليش بس ممكن تشرح لي الكود واش نقصد بالe

ولماذا كتبنا الكود في الاس كيو ال ابديتنج؟؟

شكرا في بي

تم تعديل هذه المشاركة بواسطة الحكيمة في 29 مايو 2011 في 00:36

#4

بصرااحة كنت أوول فاهمتها..مو مررة...بس الحين..فهمتها أكثر......لك الشكر أستااذ vb وبالتووفيق للساائلة...

اللهم أرزقني علما نافعا وعملا صالحا

#5

السلام عليكم ورحمه الله وبركاته

لاشكر على واجب اختي وبالتوفيق للجميع ..

.:: Wish to become better and better ::.

#6

طيب اخوي بالنسبه للCType اش هي

وكمان سؤال في الكود الاتي

Protected Sub SqlDataSource2_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource2.Updating
        Dim memIdLabel As Label = CType(DetailsView1.FindControl("lblMember"), Label)
        e.Command.Parameters.Clear()
        Dim memIdParam As SqlParameter = New SqlParameter("@MemberID", SqlDbType.Int)
        memIdParam.Direction = ParameterDirection.Input
        memIdParam.Value = Convert.ToInt32(memIdLabel.Text.Trim())

        e.Command.Parameters.Add(memIdParam)

plain text End Sub

معليش بس ممكن تشرح لي الكود واش نقصد بالe

ولماذا كتبنا الكود في الاس كيو ال ابديتنج؟؟

شكرا في بي

#7

السلام عليكم ورحمه الله وبركاته

اختي الكود السابق يحدث عند تنفيذ عملية التحديث في ال SqlDataSource اما بالنسبه ل CType تقوم بالتحويل من نوع لأخر فمثلا في مثالك تقوم بالبحث عن مربع عنوان اسمه lblMember وتحول الكائن الى فئه من نوع Label

.:: Wish to become better and better ::.

#8

معليش عندي كود سي شارب للتصويت مافهمته ممكن احد يوضح لي اياه

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

public partial class Poll : System.Web.UI.UserControl
{
    #region Public Properties
    public int PollID
    {
        get 
        {
            if (ViewState["PollID"] == null)
                return -1;
            else
                return (int)ViewState["PollID"];
        }
        set { ViewState["PollID"] = value; }
    }

    public bool PollEnabled
    {
        get
        {
            if (ViewState["PollEnabled"] == null)
                return true;
            else
                return (bool)ViewState["PollEnabled"];
        }
        set { ViewState["PollEnabled"] = value; }
    }
    #endregion

    #region SqlDataSource Control Event Handlers
    /*
     * The following three event handlers are used to populate the @PollID parameter
     * based on the User Control's PollID property for assorted SqlDataSource controls...
     */
    protected void PollDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@PollID"].Value = PollID;
    }
    protected void PollAnswersDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@PollID"].Value = PollID;
    }
    protected void PollResultsDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@PollID"].Value = PollID;
    }

    // Sets the @UserID parameter when voting in order to associate the currently logged on
    // user's UserId value with the vote.
    protected void PollAnswersDataSource_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
        int userID;
        if (Session["username"] != null && Session["uid"] != null && Session["role"] != null)
        {
            userID = Convert.ToInt32(Session["uid"].ToString());
            e.Command.Parameters["@MemberID"].Value = userID;
        }


    }
    #endregion

    #region PollFormView DataBound Event Handler
    // This event handler fires when data is bound to the FormView. It shows either
    // the poll taking or poll results interface depending on the result of
    // CanUserTakePoll() method. If PollEnabled is false, then the poll results are
    // always shown, regardless of what CanUserTakePoll() returns.
    // EXTENSION POINT: If you want to modify what users can take the poll (such as allowing
    //                  anonymous users), modify the CanUserTakePoll() method...)
    protected void PollFormView_DataBound(object sender, EventArgs e)
    {
        // Determine if the user can take the poll
        bool showResults;
        if (!PollEnabled)
            showResults = true;
        else
            showResults = !CanUserTakePoll();

        // Show/hide the Panels based on the value of showResults
        Panel takePollPanel = PollFormView.FindControl("pnlTakePoll") as Panel;
        if (takePollPanel != null)
            takePollPanel.Visible = !showResults;

        Panel pollResultsPanel = PollFormView.FindControl("pnlPollResults") as Panel;
        if (pollResultsPanel != null)
            pollResultsPanel.Visible = showResults;
    }
    #endregion

    #region "Vote" Button Click Event Handler
    // When the "Vote" button is clicked, this event handler executes. It calls the
    // PollAnswersDataSource's Insert() method, thereby INSERTing a record into the
    // UserResponses table. It then rebinds the data to the control, which causes the
    // poll interface to be updated, showing the poll results (since the user has now
    // taken the poll) and with the updated poll results.
    protected void btnSubmitVote_Click(object sender, EventArgs e)
    {
        SqlDataSource answersDataSource = PollFormView.FindControl("PollAnswersDataSource") as SqlDataSource;
        answersDataSource.Insert();

        PollFormView.DataBind();        // rebind the data to the poll interface
    }
    #endregion

    #region ResultsDataList Event Handlers
    // Determines how many total votes have been cast for this poll. Used to determine the
    // percentages for each answer as well as for displaying the total number of votes in
    // the TotalVotesLabel Label. 
    private int totalVotes = 0;
    protected void resultsDataList_DataBinding(object sender, EventArgs e)
    {
        // Calculate the total # of votes
        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CenterDBConnectionString"].ConnectionString))
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM PollResponses r INNER JOIN PollAnswers a ON r.PollAnswerID = a.PollAnswerID WHERE a.PollID = @PollID", conn);
            cmd.Parameters.Add(new SqlParameter("@PollID", PollID));
            totalVotes = (int)cmd.ExecuteScalar();
            conn.Close();
        }

        // Display the # of votes
        Label TotalVotesLabel = PollFormView.FindControl("TotalVotesLabel") as Label;
        TotalVotesLabel.Text = string.Format(" عدد الأصوات: {0:d}", totalVotes);
    }


    // This event handler fires once for each poll answer when viewing the results.
    // It determines the number of votes for each answer and computes and displays the percentage.
    protected void resultsDataList_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        // Determine how many votes were made for this answer...
        int votes = (int)DataBinder.Eval(e.Item.DataItem, "Votes");

        // Programmatically access the Label & Image controls...
        Label percentLabel = (Label)e.Item.FindControl("PercentageLabel");
        Image percentImage = (Image)e.Item.FindControl("PercentageImage");

        // Calculate the percentage...
        if (totalVotes > 0)
        {
            double pct = (Convert.ToDouble(votes) / Convert.ToDouble(totalVotes)) * Convert.ToDouble(100);
            percentLabel.Text = pct.ToString("0.0") + "%";
            percentImage.Width = Unit.Percentage(pct);
        }
        else
        {
            percentLabel.Text = "0%";
            percentImage.Visible = false;
        }
    }
    #endregion

    #region CanUserTakePoll Method (EXTENSION POINT)
    // Determines whether a user can take the poll or if the results must be shown.
    // My implementation only allows authenticated users who have not already taken the
    // poll to vote. 
    // EXTENSION POINT: If you want to modify what users can take the poll (such as allowing
    //                  anonymous users), modify the CanUserTakePoll() method...)
    private bool CanUserTakePoll()
    {
        // Anonymous visitors cannot take poll
        //if (!Request.IsAuthenticated)
        //    return false;
        bool auth = false;
        if (Session["username"] != null && Session["uid"] != null && Session["role"] != null)
        {
            auth = true;
        }

        if (!auth)
        {
            return false;
        }

        // Determine if this user has already taken this poll... if so, she cannot retake it.
        //MembershipUser currentUser = Membership.GetUser();
        if (auth)
        {
            int userID = Convert.ToInt32(Session["uid"].ToString());
            bool hasUserTakenPoll = false;

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CenterDBConnectionString"].ConnectionString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM PollResponses r INNER JOIN PollAnswers a ON r.PollAnswerID = a.PollAnswerID WHERE a.PollID = @PollID AND r.MemberID = @MemberID", conn);
                cmd.Parameters.Add(new SqlParameter("@PollID", PollID));
                cmd.Parameters.Add(new SqlParameter("@MemberID", userID));

                hasUserTakenPoll = ((int)cmd.ExecuteScalar()) > 0;
                conn.Close();
            }

            return hasUserTakenPoll == false;
        }

        return false;
    }
    #endregion
    protected void PollFormView_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {

    }
}
#9

السلام عليكم ورحمه الله وبركاته

اختي سؤالك لاعلاقه له بالموضوع الاصلي؟!! وبرضه حددي الجزء المراد شرحه ضروري ستفيدي برضه!!

.:: Wish to become better and better ::.

مواضيع مشابهة