Dear Experts,
I found this awesome code from aspsnippets site and I am having problem modifying to meet my needs.
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"
ddlStatus.DataBind()
Dim SatusName As ListItem = ddlStatus.Items.FindByValue("lblStatus")
If SatusName IsNot Nothing Then
ddlDepts.SelectedValue = SatusName.Value
End If
End If
End Sub
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.