I am inserting a record into the database using the following statement and was wondering how I could get the ID of that record inserted. Here is my statement.
myConnection = New SqlConnection(""
strUpdateStmt = "Insert monkeys (loginID, thedate, fromemp, toemp, employeename, dollaramount, comments) Values (@loginID, @date, @fromemp, @toemp, @employee, @dollaramount, @comments)"
myCommand = new SqlCommand(strUpdateStmt, myConnection)
mycommand.Parameters.Add("@loginID", SqlDBType.nvarchar, 50).Value = employees.SelectedItem.value
mycommand.Parameters.Add("@date", SqlDBType.smalldatetime).Value = pagedate.text
mycommand.Parameters.Add("@fromemp", SqlDBType.nvarchar, 50).Value = fromemp
mycommand.Parameters.Add("@toemp", SqlDBType.nvarchar, 50).Value = supervisor.text
mycommand.Parameters.Add("@employee", SqlDBType.nvarchar, 50).Value = employeesname.text
mycommand.Parameters.Add("@dollaramount", SqlDBType.money).Value = dollar.text
mycommand.Parameters.Add("@comments", SqlDBType.text).Value = comments.text
myConnection.open()
myCommand.ExecuteNonQuery()
myConnection.close()
Is there a way to have it return the id in this statement?
myConnection = New SqlConnection(""
strUpdateStmt = "Insert monkeys (loginID, thedate, fromemp, toemp, employeename, dollaramount, comments) Values (@loginID, @date, @fromemp, @toemp, @employee, @dollaramount, @comments)"
myCommand = new SqlCommand(strUpdateStmt, myConnection)
mycommand.Parameters.Add("@loginID", SqlDBType.nvarchar, 50).Value = employees.SelectedItem.value
mycommand.Parameters.Add("@date", SqlDBType.smalldatetime).Value = pagedate.text
mycommand.Parameters.Add("@fromemp", SqlDBType.nvarchar, 50).Value = fromemp
mycommand.Parameters.Add("@toemp", SqlDBType.nvarchar, 50).Value = supervisor.text
mycommand.Parameters.Add("@employee", SqlDBType.nvarchar, 50).Value = employeesname.text
mycommand.Parameters.Add("@dollaramount", SqlDBType.money).Value = dollar.text
mycommand.Parameters.Add("@comments", SqlDBType.text).Value = comments.text
myConnection.open()
myCommand.ExecuteNonQuery()
myConnection.close()
Is there a way to have it return the id in this statement?