TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sie Ste
NA
196
184.1k
C# not update table correctly
Sep 8 2012 9:21 PM
I am having a problem using linq to sql in a C# desktop application that connects to sql server 2008. Basically if the CustId already exists in the Trans table, I do not want to insert a new row into the table. However the code listed below does not work.
**Note the CustId is not the primary key of the table. there is an identity key that is the primary key of the table.
eDataContext rptData = new eDataContext();
var eupdate = (from a in rptData.Tran
where a.Cust_ID == CustId
select a).SingleOrDefault();
if (eupdate != null)
{
log.Info(CustId + "already exists in the Trans table");
}
else
{
Trans subCustid = null;
subCustid = new Trans();
subCustid.Package_ID = pkgid;
rptData.Trans.InsertOnSubmit(subCustid);
rptData.SubmitChanges();
}
Thus can you tell me what I can do to not allow a row to be inserted into the Trans table when the CustId already exists in the table?
Reply
Answers (
3
)
how can get status report from sms application
C# accessing several proejct folders in same solution issue