Update table help

R

Ron

Hello,

I am trying to do a simple update on employee information. I am a
novice at both aspx and SQLServer, so I hope you are not too offended
by my code. The following is the update code:

--Start of code--
dim objConnection as SqlConnection
dim daAddEmp as SqlDataAdapter
dim strconnection as string = "myserverlocation"
objconnection = New SqlConnection(strConnection)
dim strSQL as String = "SELECT * FROM employees"
dim daEditEmp as New SqlDataAdapter(strSQL, objConnection)
dim dsTemp as New Dataset()
daEditEmp.Fill(dsTemp, "editemployee")

dim tbl as DataTable = dsTemp.Tables("editemployee")
tbl.PrimaryKey = New DataColumn() _
{ tbl.Columns("emp_id") }

dim row as DataRow = tbl.Rows.Find(session("empid"))
Row.Item("Emp_Num") = EmpNum.text
Row.Item("Emp_Last") = empLast.text
Row.Item("Emp_First") = empFirst.text
Row.Item("Emp_Title") = empTitle.text
Row.Item("Emp_Dept") = empDept.text
Row.Item("Emp_Site") = empSite.selecteditem.value
Row.Item("Emp_Add") = empAdd.text
Row.Item("Emp_Work") = empWork.text
Row.Item("Emp_Fax") = empFax.text
Row.Item("Emp_Home") = empHome.text
Row.Item("Emp_Email") = empEmail.text
Row.Item("Emp_Mgr") = empMgr.text
Row.Item("Emp_Mgr_Phone") = empMgrnum.text
Row.Item("Emp_Pass") = emppass.text

dim cb as New SqlCommandBuilder(daEditEmp)
objConnection.Open()
daEditEmp.Update(dsTemp, "editemployee")
objconnection.close()
fill_page() 'calls procedure to repopulate fields
--end of code--

I appreciate any and all help. Thanks.

--Ron
 
C

Curt_C [MVP]

I'd suggest an "update table...." as opposed to a "select " and then
..Update.
You will find life will be MUCH easier.
 
R

Ron

Hey Curt,

Thanks for the response. Your suggestion is noted. As it turns out,
after I implemented your suggestion the update still would not work. I
finally find the mistake though. The same 'fill_page()' procedure I
call at the end of the update procedure is called in the page_load
procedure... w/o a postback if/then!! So I was replacing the updated
data w/ the existing data and therefore 'updating' w/ the unchanged
info. Oh well, novice mistake. Hopefully somebody else will learn
from this post. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top