Hi, Good morining every one.
I am able to insert a record but not able to update it.
I have to update the records in TANLUSR_DUP based on USR_ID which is the P.Key in this table.
How do I write a code for the following function.
Update table TANLUSR_DUP where Data set. user_id = TANLUSR_DUP.USR_ID
Please find the code I am using.
Any help is appreciated.
using System;using System.Collections.Generic;using System.ComponentModel;using System.Diagnostics;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Text;using System.Windows.Forms;using GetLDAPProfile.LDAP;
namespace GetLDAPProfile{ public partial class Form1 : Form { public Form1() { InitializeComponent();
UserProfileRecord objProfile = new UserProfileRecord();
UserProfileService usrPrSvc = new UserProfileService();
UserProfileRequest objUPRq = new UserProfileRequest(); UserProfileResult objUPRslt = new UserProfileResult();
string cnStr = "Database=SA0;Server=s3b73;UID=sec;pwd=security";
SqlConnection cn = new SqlConnection(); cn.ConnectionString = cnStr;
string strSQLTxt = "select usr_nr from TANLUSR_DUP where itx_usr_typ_cd is null";
SqlDataAdapter da = new SqlDataAdapter(strSQLTxt, cn);
DataSet ds = new DataSet();
da.Fill(ds);
da.SelectCommand.CommandText = "select * from TANLUSR_DUP";
SqlCommandBuilder cmdBldr = new SqlCommandBuilder(da);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey; da.Fill(ds, "TANLUSR_DUP");
foreach (DataRow row in ds.Tables[0].Rows) { objUPRq.UserID = row.ItemArray[0].ToString(); objUPRq.IDType = "uuid"; objUPRslt = usrPrSvc.getUserProfile(objUPRq); if (objUPRslt.count != 0) { objProfile = objUPRslt.record[0]; Debug.WriteLine( String.Format("uuid: {0,-10}\t" + "Employee Number: {1,-10}\t" + "Phone: {5,-11}" + "Region: {2,-3}\t" + "District: {3,-3}\t" + "Center: {4,-8}", objProfile.uuid, objProfile.empid, objProfile.region, objProfile.district, objProfile.center, objProfile.telephone));
DataRow NewRow = ds.Tables["TANLUSR_DUP"].NewRow();
NewRow[0] = objProfile.uuid; NewRow[1] = objProfile.empid; NewRow[20] = objProfile.telephone; NewRow[21] = objProfile.region; NewRow[22] = objProfile.district; NewRow[23] = objProfile.center; NewRow[24] = objProfile.company; NewRow[25] = objProfile.country; NewRow[26] = objProfile.jclass; NewRow[27] = objProfile.jfunction; NewRow[28] = objProfile.jgroup; NewRow[29] = objProfile.emptype; NewRow[30] = objProfile.department;
ds.Tables["TANLUSR_DUP"].Rows.Add(NewRow); da.Update(ds.Tables["TANLUSR_DUP"]);
} }
} }}