Click here to Skip to main content
       

Database

 
QuestionxBase question PinmemberDavidCrow14-May-12 10:05 
AnswerRe: xBase question PinmemberKevin Marois14-May-12 11:40 
QuestionRe: xBase question PinmemberDavidCrow14-May-12 17:22 
AnswerRe: xBase question PinmemberKevin Marois15-May-12 6:35 
QuestionRe: xBase question PinmemberDavidCrow15-May-12 6:55 
AnswerRe: xBase question [modified] PinmemberKevin Marois15-May-12 7:01 
GeneralRe: xBase question PinmemberDavidCrow15-May-12 7:30 
GeneralRe: xBase question PinmemberKevin Marois15-May-12 7:31 
GeneralRe: xBase question PinmemberDavidCrow15-May-12 7:37 
GeneralRe: xBase question PinmemberKevin Marois15-May-12 7:44 
QuestionOracle: Replace single occurrence of a character PinmemberLash2014-May-12 8:21 
AnswerRe: Oracle: Replace single occurrence of a character Pinmemberrana ray15-May-12 0:56 
GeneralLinq to Sql Pinmembersindhuan14-May-12 1:10 
GeneralRe: Linq to Sql [modified] PinmemberKevin Marois14-May-12 11:45 
sindhuan wrote:
Is this the right way to do??

 
No, because
 
dc.users.InsertOnSubmit("us");
 
won't even compile, because you're trying to insert a string "ur". Your code is expecting an entity of type user. So you want
 
dc.users.InsertOnSubmit(us);
 
So, you first want to query the user to get the name, then insert the new row.
 
using (MyDataContext dc = new MyDataContext())
{
    var userName = (from u in dc.tblUsers
                    where u.Id = someId
                    select u.UserName).FirstOrDefault();
 

    user us = new user
    {
        Date = DateTime.Now,
        name = userName
    };
 
    try
    {
        dc.users.InsertOnSubmit(us);
    }
    catch(Exception e)
    {
        // Handle exception here
    }
}
 
You will have to adjust the data context and table names and column names, but this should get you started.
If it's not broken, fix it until it is


modified 14-May-12 18:00pm.

QuestionDoubt in a piece of code [Transact-SQL database audit]. [modified] PinmembervValkir13-May-12 21:54 
AnswerRe: Doubt in a piece of code [Transact-SQL database audit]. PinmemberMycroft Holmes13-May-12 22:36 
GeneralRe: Doubt in a piece of code [Transact-SQL database audit]. PinmembervValkir13-May-12 22:54 
AnswerRe: Doubt in a piece of code [Transact-SQL database audit]. Pinmemberdjj5514-May-12 4:08 
QuestionOracle Question: Split String into two PinmemberLash2011-May-12 5:57 
AnswerRe: Oracle Question: Split String into two PinmemberJörgen Andersson11-May-12 9:08 
AnswerRe: Oracle Question: Split String into two PinmemberLash2011-May-12 9:33 
GeneralRe: Oracle Question: Split String into two PinmemberJörgen Andersson11-May-12 9:47 
Questiontimestamp Pinmembervijaylumar11-May-12 1:39 
AnswerRe: timestamp PinmemberEddy Vluggen11-May-12 1:42 
QuestionWhat is database SQL query to display the name of the table only in to datagrid? PinmemberLAPEC10-May-12 1:04 
AnswerRe: What is database SQL query to display the name of the table only in to datagrid? PinmemberPIEBALDconsult10-May-12 3:16 
AnswerRe: What is database SQL query to display the name of the table only in to datagrid? Pinmembervvashishta10-May-12 4:17 
GeneralRe: What is database SQL query to display the name of the table only in to datagrid? PinmemberEddy Vluggen10-May-12 7:05 
Questionchoosing a database Pinmemberdavood_b8-May-12 1:19 
AnswerRe: choosing a database PinmemberPIEBALDconsult8-May-12 3:16 
QuestionRe: choosing a database PinmemberEddy Vluggen8-May-12 5:05 
GeneralRe: choosing a database PinmemberPIEBALDconsult8-May-12 18:42 
AnswerRe: choosing a database PinmemberEddy Vluggen8-May-12 5:08 
Questionusing xquery to populate a table variable in sql Pinmemberswjam6-May-12 4:34 
QuestionRead LFD(log ) file SQLserver 2008 Pinmemberjojoba20114-May-12 17:38 
AnswerRe: Read LFD(log ) file SQLserver 2008 PinmemberEddy Vluggen4-May-12 23:11 
QuestionRe: Read LFD(log ) file SQLserver 2008 Pinmemberjojoba20114-May-12 23:19 
AnswerRe: Read LFD(log ) file SQLserver 2008 PinmemberEddy Vluggen4-May-12 23:31 
GeneralRe: Read LFD(log ) file SQLserver 2008 Pinmemberjojoba20115-May-12 20:31 
GeneralRe: Read LFD(log ) file SQLserver 2008 PinmemberMycroft Holmes5-May-12 23:00 
JokeRe: Read LFD(log ) file SQLserver 2008 PinmemberEddy Vluggen6-May-12 6:08 
AnswerRe: Read LFD(log ) file SQLserver 2008 PinmemberEddy Vluggen6-May-12 0:37 
GeneralRe: Read LFD(log ) file SQLserver 2008 Pinmemberjojoba20116-May-12 23:30 
AnswerRe: Read LFD(log ) file SQLserver 2008 PinmemberEddy Vluggen7-May-12 0:30 
GeneralRe: Read LFD(log ) file SQLserver 2008 Pinmemberjojoba20117-May-12 17:37 
GeneralRe: Read LFD(log ) file SQLserver 2008 PinmemberJohnPayton7-May-12 18:10 
GeneralRe: Read LFD(log ) file SQLserver 2008 PinmemberEddy Vluggen8-May-12 0:17 
QuestionRe: Read LFD(log ) file SQLserver 2008 Pinmemberjojoba20119-May-12 17:52 
AnswerRe: Read LFD(log ) file SQLserver 2008 PinmemberEddy Vluggen10-May-12 0:07 
QuestionRe: Read LFD(log ) file SQLserver 2008 Pinmemberjojoba201111-May-12 17:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 18 Sep 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid