I am not sure how to fix this??
Imports
System.DataImports
System.Web.UI.WebControls.FormViewImports
System.Data.SqlClientPartial
Class AssignmentInherits System.Web.UI.PageProtectedSub UpdateButton_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles UpdateButton.ClickDim empIDAsIntegerDim nbrIDAsIntegerDim equidAsIntegerDim UpdateQueryDim empequipidAs SqlCommandDim mySQLConnectionAsString = System.Configuration.ConfigurationManager.ConnectionStrings("DBConnectionString").ToStringDim myConnectionAsNew SqlConnection(mySQLConnection)myConnection.Open()
empID = (Session(
"UserEmployeeID"))equid = (Session(
"UserEquipID"))IfCType(empID,Integer) =NothingThenempID = (DropDownList1.SelectedValue)
'Response.Write("Insert: " & empID)'Response.End()Me.SqlDataSource1.InsertCommand ="INSERT INTO [EMPLOYEES_EQUIP] ([EquipID], [EmployeeID]) VALUES " & equid &" " & empID &""Me.SqlDataSource1.InsertCommand = SqlDataSourceCommandType.TextMe.SqlDataSource1.Insert()Elseempequipid =
New SqlCommand("Select EmpEquipID From EMPLOYEES_EQUIP Where EmployeeID = " & empID &" AND EquipID = " & equid &" ", myConnection)empequipid.CommandType = CommandType.Text
nbrID = empequipid.ExecuteScalar
'Response.Write("Select EmpEquipID: " & nbrID)'Response.End()empID = (DropDownList1.SelectedValue)
'Response.Write("<br>Update EmployeeID: " & empID)'Response.End()Me.SqlDataSource1.UpdateCommand ="UPDATE EMPLOYEES_EQUIP SET EmployeeID = " & empID &" WHERE EmpEquipID = " & nbrID &" "Me.SqlDataSource1.UpdateCommand = SqlDataSourceCommandType.TextMe.SqlDataSource1.Update() <--Right here is displaying "Incorrect syntax near '0'."'Added to output the Update QueryUpdateQuery =
"UPDATE EMPLOYEES_EQUIP SET EmployeeID = " & empID &" WHERE EmpEquipID = " & nbrID &" "'Response.Write(UpdateQuery)'Response.End()EndIf'Updating the session to new EmployeeIDSession(
"UserEployeeID") = (DropDownList1.SelectedValue)'Response.Write("<br>UserEmployeeID Session: " & Session("UserEmployeeID"))'Response.End()'-- Turn On Employee Information TableEmpInfo.Visible =
True'-- Hides the Employee Name's Drop Down List table.maintable.Visible =
FalseEndSubEnd
ClassThis will not generate a valid SQL statement. Missing parenthesis, values are separated by commas not spaces, and containts a possible security hole:
Me.SqlDataSource1.InsertCommand ="INSERT INTO [EMPLOYEES_EQUIP] ([EquipID], [EmployeeID]) VALUES " & equid &" " & empID &""
This is setting the wrong property:
Me.SqlDataSource1.InsertCommand = SqlDataSourceCommandType.Text
The & " " at the end of this is unneccessary, as well as contains a possible secutiy hole:
Me.SqlDataSource1.UpdateCommand ="UPDATE EMPLOYEES_EQUIP SET EmployeeID = " & empID &" WHERE EmpEquipID = " & nbrID &" "
This sets the wrong property, and the cause of your error message:
Me.SqlDataSource1.UpdateCommand = SqlDataSourceCommandType.Text
The following is redundant code (Exists in both IF paths and should be moved outside of the if):
empID = (DropDownList1.SelectedValue)
The following is useless code and isn't referenced anywhere. Should comment it out, or remove:
UpdateQuery =
"UPDATE EMPLOYEES_EQUIP SET EmployeeID = " & empID &" WHERE EmpEquipID = " & nbrID &" "
Useless & " " at end, and possible security hole:
empequipid =
New SqlCommand("Select EmpEquipID From EMPLOYEES_EQUIP Where EmployeeID = " & empID &" AND EquipID = " & equid &" ", myConnection)
The following wasn't assigned a type (String?) and becomes unneeded once the above changes have been made:
Dim UpdateQuery
|||ahh I got it to work now! Thank you!
No comments:
Post a Comment