Click here to Skip to main content
       

Database

 
GeneralRe: xBase question PinmemberDavidCrow15-May-12 8:30 
GeneralRe: xBase question PinmemberKevin Marois15-May-12 8:31 
GeneralRe: xBase question PinmemberDavidCrow15-May-12 8:37 
GeneralRe: xBase question PinmemberKevin Marois15-May-12 8:44 
QuestionOracle: Replace single occurrence of a character PinmemberLash2014-May-12 9:21 
AnswerRe: Oracle: Replace single occurrence of a character Pinmemberrana ray15-May-12 1:56 
GeneralLinq to Sql Pinmembersindhuan14-May-12 2:10 
GeneralRe: Linq to Sql [modified] PinmemberKevin Marois14-May-12 12: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 22:54 
AnswerRe: Doubt in a piece of code [Transact-SQL database audit]. PinmemberMycroft Holmes13-May-12 23:36 
GeneralRe: Doubt in a piece of code [Transact-SQL database audit]. PinmembervValkir13-May-12 23:54 
AnswerRe: Doubt in a piece of code [Transact-SQL database audit]. Pinmemberdjj5514-May-12 5:08 
QuestionOracle Question: Split String into two PinmemberLash2011-May-12 6:57 
AnswerRe: Oracle Question: Split String into two PinmemberJörgen Andersson11-May-12 10:08 
AnswerRe: Oracle Question: Split String into two PinmemberLash2011-May-12 10:33 
GeneralRe: Oracle Question: Split String into two PinmemberJörgen Andersson11-May-12 10:47 
Questiontimestamp Pinmembervijaylumar11-May-12 2:39 
AnswerRe: timestamp PinmemberEddy Vluggen11-May-12 2:42 
QuestionWhat is database SQL query to display the name of the table only in to datagrid? PinmemberLAPEC10-May-12 2:04 
AnswerRe: What is database SQL query to display the name of the table only in to datagrid? PinmemberPIEBALDconsult10-May-12 4:16 
AnswerRe: What is database SQL query to display the name of the table only in to datagrid? Pinmembervvashishta10-May-12 5:17 
GeneralRe: What is database SQL query to display the name of the table only in to datagrid? PinmemberEddy Vluggen10-May-12 8:05 
Questionchoosing a database Pinmemberdavood_b8-May-12 2:19 
AnswerRe: choosing a database PinmemberPIEBALDconsult8-May-12 4:16 
QuestionRe: choosing a database PinmemberEddy Vluggen8-May-12 6:05 

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
Web04 | 2.8.141220.1 | Last Updated 19 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid