Last post Feb 13, 2017 06:42 PM by simflex
Feb 13, 2017 05:44 PM|simflex|LINK
Hello again experts,
Anyone has any idea how to fix this?
I have two tables, Status and main
Status has two fields, StatusID, int (PK) and status nvarchar(15)
main has statusID int (FK) references StatusID in Status table and other fields,
Obviously, when you save records to the main table, StatusID, NOT status is saved to main for later joins.
The code below is giving me incorrect syntax near ')'
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim statuscmd As New SqlCommand("SELECT StatusID,Status) FROM Status")
Dim ddlStatus As DropDownList = TryCast(e.Row.FindControl("ddlStatus"), DropDownList)
ddlStatus.DataSource = Me.ExecuteQuery(statuscmd, "SELECT")
ddlStatus.DataTextField = "StatusID"
ddlStatus.DataValueField = "Status"
Dim SatusName As ListItem = ddlStatus.Items.FindByValue("lblStatus")
If SatusName IsNot Nothing Then
ddlDepts.SelectedValue = SatusName.Value
I am getting that error because I am trying to save StatusID to the main table.
If I replace StatusID with Status, the error goes away.
However, we can't insert Status into main table.
How do I fix this code to accept StatusID instead of Status?
Thanks as always for your assistance.
Feb 13, 2017 05:55 PM|PatriceSc|LINK
No. For now this is because you have an extra ) in your SQL statement :
SELECT StatusID,Status) FROM Status
Also this is likkely an SqlException so it allows to understand that this is a SQL side syntax error and so a problem in your SQL statement.
Feb 13, 2017 06:09 PM|Sumit.Pokhriyal|LINK
There is extra ")" in your select statement => SELECT StatusID,Status) FROM Status
Dim statuscmd As New SqlCommand("SELECT StatusID,Status FROM Status")
Feb 13, 2017 06:13 PM|simflex|LINK
If you recall, I had similar problem last week and when the error was incorrect syntax near ','
So, I immediately assumed it was similar problem.
Thank you so much.
Now, it shows the ID on the screen instead of status name.
I would like to show status name on the screen but save status ID.
Is there something I can change on the code?
Feb 13, 2017 06:17 PM|Sumit.Pokhriyal|LINK
Reverse the columns. See below:
ddlStatus.DataTextField = "Status" //text to display
ddlStatus.DataValueField = "StatusID" //value as identifier
Feb 13, 2017 06:42 PM|simflex|LINK
I am just not thinking now.
Too tense, I suppose.
I didn't pay attention to these:
I usually have them in reverse.
Thank you very much to you and Patrice