รบกวนปรึกษาเกิดจากการเปลี่ยน AccessDataSource มาเป็น SqlDataSource
2 posters
หน้า 1 จาก 1
รบกวนปรึกษาเกิดจากการเปลี่ยน AccessDataSource มาเป็น SqlDataSource
สวัสดีครับอาจารย์รบกวนปรึกษาเกิดจากการเปลี่ยน AccessDataSource มาเป็น SqlDataSource ของคลาส UserEdit กับ UserInsert หน่อยครับ
ขออ้างอิงจากโค้ดอาจารย์ที่อาจารย์สอนไว้น่ะครับใน UserEdit.aspx
คือผมเปลี่ยนเฉพาะในส่วนของ
จากเดิมทีที่เป็น AccessDataSource ดังนี้ครับ
(ขออนุญาติ ดึงโค้ดมาเขียนสั้นๆน่ะครับเพราะผมเปลี่ยนแค่ตรงนี้จริงๆครับ และไม่อยากใส่โค้ดเต็มๆใ้ห้หน้าโพสถามนี้ยาวไป)
<asp:FormView ID="FormView1" runat="server" ...... DataSourceID="AccessDataSource1" ......
แล้วผมนำมาเปลี่ยนมาเป็น SqlDataSource ดังนี้ครับ
<asp:FormView ID="FormView1" runat="server" ...... DataSourceID="SqlDataSource1" ......
และในส่วนของ AccessDataSource
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="D:\WebTestSql\App_Data\thailand2siam.mdb;"
..................
</asp:AccessDataSource >
มาเป็น
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WebTestSqlConnectionString %>"
.........
</asp:SqlDataSource>
ตามที่หนังสือของอาจารย์แนะนำไว้ครับ พอผม run มันฟ้องว่า
Server Error in '/WebTestSql' Application.
--------------------------------------------------------------------------------
Incorrect syntax near '?'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '?'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
ผมเลยคิดว่าอาจจะเป็นที่ตรง
SelectCommand="SELECT * FROM [UserData] WHERE ([UserID] = ?)"
DeleteCommand="DELETE FROM [UserData] WHERE [UserID] = ?"
InsertCommand="INSERT INTO [UserData] ([UserID], [UserName], [UserSName], [UserEmail], [UserStreet], [UserCity], [UserZip], [UserCountry], [UserTel], [UserMobile], [UserFax], [UserPassWord], [UserStatus]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
UpdateCommand="UPDATE [UserData] SET [UserName] = ?, [UserSName] = ?, [UserEmail] = ?, [UserStreet] = ?, [UserCity] = ?, [UserZip] = ?, [UserCountry] = ?, [UserTel] = ?, [UserMobile] = ?, [UserFax] = ?, [UserPassWord] = ?, [UserStatus] = ? WHERE [UserID] = ?">
แต่ตอนที่ใช้ AccessDataSource ก็สามารถรันได้ปกติครับไม่มีปัญหาใดๆครับ หรือว่าผมมาเปลี่ยนเป็น SqlDataSource ผมต้องเปลี่ยนตรงเครื่องหมาย ? ให้เป็นอย่างอื่นหรือป่าวครับ ขอรบกวนอาจารย์ด้วยน่ะครับ
ขอขอบพระคุณครับ
ขออ้างอิงจากโค้ดอาจารย์ที่อาจารย์สอนไว้น่ะครับใน UserEdit.aspx
คือผมเปลี่ยนเฉพาะในส่วนของ
จากเดิมทีที่เป็น AccessDataSource ดังนี้ครับ
(ขออนุญาติ ดึงโค้ดมาเขียนสั้นๆน่ะครับเพราะผมเปลี่ยนแค่ตรงนี้จริงๆครับ และไม่อยากใส่โค้ดเต็มๆใ้ห้หน้าโพสถามนี้ยาวไป)
<asp:FormView ID="FormView1" runat="server" ...... DataSourceID="AccessDataSource1" ......
แล้วผมนำมาเปลี่ยนมาเป็น SqlDataSource ดังนี้ครับ
<asp:FormView ID="FormView1" runat="server" ...... DataSourceID="SqlDataSource1" ......
และในส่วนของ AccessDataSource
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="D:\WebTestSql\App_Data\thailand2siam.mdb;"
..................
</asp:AccessDataSource >
มาเป็น
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WebTestSqlConnectionString %>"
.........
</asp:SqlDataSource>
ตามที่หนังสือของอาจารย์แนะนำไว้ครับ พอผม run มันฟ้องว่า
Server Error in '/WebTestSql' Application.
--------------------------------------------------------------------------------
Incorrect syntax near '?'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '?'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
ผมเลยคิดว่าอาจจะเป็นที่ตรง
SelectCommand="SELECT * FROM [UserData] WHERE ([UserID] = ?)"
DeleteCommand="DELETE FROM [UserData] WHERE [UserID] = ?"
InsertCommand="INSERT INTO [UserData] ([UserID], [UserName], [UserSName], [UserEmail], [UserStreet], [UserCity], [UserZip], [UserCountry], [UserTel], [UserMobile], [UserFax], [UserPassWord], [UserStatus]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
UpdateCommand="UPDATE [UserData] SET [UserName] = ?, [UserSName] = ?, [UserEmail] = ?, [UserStreet] = ?, [UserCity] = ?, [UserZip] = ?, [UserCountry] = ?, [UserTel] = ?, [UserMobile] = ?, [UserFax] = ?, [UserPassWord] = ?, [UserStatus] = ? WHERE [UserID] = ?">
แต่ตอนที่ใช้ AccessDataSource ก็สามารถรันได้ปกติครับไม่มีปัญหาใดๆครับ หรือว่าผมมาเปลี่ยนเป็น SqlDataSource ผมต้องเปลี่ยนตรงเครื่องหมาย ? ให้เป็นอย่างอื่นหรือป่าวครับ ขอรบกวนอาจารย์ด้วยน่ะครับ
ขอขอบพระคุณครับ
nattaromn- จำนวนข้อความ : 18
Join date : 10/01/2010
ขอบพระคุณมากๆครับอาจารย์
อ้อ.. เข้าใจแล้วครับอาจารย์ ขอขอบพระคุณมากๆเลยครับ
ตอนนี้สามารถแก้ได้แล้วครับ ^^ ขอบคุณครับ
ตอนนี้สามารถแก้ได้แล้วครับ ^^ ขอบคุณครับ
nattaromn- จำนวนข้อความ : 18
Join date : 10/01/2010
หน้า 1 จาก 1
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ
|
|