View Single Post
ישן 28-04-06, 16:25   # 1
alex
חבר וותיק
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: הרצליה
הודעות: 1,000
שלח הודעה באמצעות MSN אל alex

alex לא מחובר  

בעיה בפקד SqlDataSourceו

שלום

יש לי משימה, להוסיף למסד נתונים של MSSQL רשומה בעזרת הפקד SqlDataSource.

אני יוצר את הפקד [הנה הקוד המתקבל]



קוד:
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        InsertCommand="INSERT INTO customers(customerID) VALUES (newparameter)" SelectCommand="SELECT [customerID] FROM [customers]">
                      

<InsertParameters>
                            <asp:ControlParameter ControlID="customerIDtxt" Name="newparameter" PropertyName="Text" />
                        </InsertParameters>
                    </asp:SqlDataSource>

כאשר יש פרמטר שאמור להכנס לVALUES, שעורכו של הפרטמטר הוא בעצם תיבת הטקסט.
אולם כשאני מריץ את הקוד מופיע השגיאה:




קוד:
The name "newparameter" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.


כשאני מנסה ישר לכתוב את תיבת הטקסט, כלומר:


קוד:
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                        InsertCommand="INSERT INTO customers(customerID) VALUES (customerIDtxt.text)" SelectCommand="SELECT [customerID] FROM [customers]">


מופיע אותה שגיאה, בהחלפת המילהnewparameter בTEXTBOX.

זהוי הפקודה בעת לחיצה על לחצן:



קוד:
Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs)
        SqlDataSource2.Insert()
    End Sub
  Reply With Quote