28-04-2006, 16:20
|
|
|
חבר מתאריך: 10.12.05
הודעות: 545
|
|
בעיה בפקד SqlDataSource [ASP.NET]
שלום
לא ידעתי איפה לכתוב זאת, מאחר פורום ASP מופקא, ומדובר כאן בניית אתרים אנסה את מזלי.
יש לי משימה, להוסיף למסד נתונים של 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.WizardNavigationEventArg s)
SqlDataSource2.Insert()
End Sub
|