Laploy Web Board
Would you like to react to this message? Create an account in a few clicks or log in to continue.

รบกวนปรึกษาเกิดจากการเปลี่ยน AccessDataSource มาเป็น SqlDataSource

2 posters

Go down

รบกวนปรึกษาเกิดจากการเปลี่ยน AccessDataSource มาเป็น SqlDataSource Empty รบกวนปรึกษาเกิดจากการเปลี่ยน AccessDataSource มาเป็น SqlDataSource

ตั้งหัวข้อ  nattaromn 2nd February 2010, 1:10 pm

สวัสดีครับอาจารย์รบกวนปรึกษาเกิดจากการเปลี่ยน 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 ผมต้องเปลี่ยนตรงเครื่องหมาย ? ให้เป็นอย่างอื่นหรือป่าวครับ ขอรบกวนอาจารย์ด้วยน่ะครับ

ขอขอบพระคุณครับ
Smile

nattaromn

จำนวนข้อความ : 18
Join date : 10/01/2010

ขึ้นไปข้างบน Go down

รบกวนปรึกษาเกิดจากการเปลี่ยน AccessDataSource มาเป็น SqlDataSource Empty credential

ตั้งหัวข้อ  Admin 2nd February 2010, 10:33 pm

ให้ตรวจชื่อ เส้นทาง และ credential ของ SQL Server ครับ

Admin
Admin

จำนวนข้อความ : 215
Join date : 17/12/2009

http://laploy.forumotion.com

ขึ้นไปข้างบน Go down

รบกวนปรึกษาเกิดจากการเปลี่ยน AccessDataSource มาเป็น SqlDataSource Empty ขอบพระคุณมากๆครับอาจารย์

ตั้งหัวข้อ  nattaromn 3rd February 2010, 12:49 am

อ้อ.. เข้าใจแล้วครับอาจารย์ ขอขอบพระคุณมากๆเลยครับ Very Happy
ตอนนี้สามารถแก้ได้แล้วครับ ^^ ขอบคุณครับ

nattaromn

จำนวนข้อความ : 18
Join date : 10/01/2010

ขึ้นไปข้างบน Go down

ขึ้นไปข้างบน


 
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ