Connecting Tech Pros Worldwide Help | Site Map

Problem in using LINQ to SQL

Newbie
 
Join Date: Jul 2008
Posts: 2
#1: Jul 19 '08
I am doing my project using LINQ to SQL technology for the database part. I wrote the coding for inserting a new record into the table. The coding was ok. Its working 100%. But after inserting the data into the table when I run next time in the Visual studio 2008 I cound'nt get the previously inserted data. Which means only in that instance I register, I was able to get the inserted data.

Also there is another problem. I have the Users.mdf file. When I open it to see the inserted records its not there. If you want to see the coding, here is it.

try
{


UsersDBDataContext context = new UsersDBDataContext();
var usersData =
from Usr in context.Users
where Usr.UserName == txtSignUpUserName.Text
select new { Usr.UserName };

if (usersData.Count() == 0)
{



User newUser = new User
{
RealName = txtRName.Text,
UserName = txtSignUpUserName.Text,
Password = pwbSignUpPassword.Password,
Country = ComCountry.Text,



};
context.Users.InsertOnSubmit(newUser);


context.SubmitChanges();


}
else
MessageBox.Show("User name already exists");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


Can any body help me with this???????
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Jul 19 '08

re: Problem in using LINQ to SQL


Where's the part that insert the record?

-- CK
Newbie
 
Join Date: Jul 2008
Posts: 2
#3: Jul 20 '08

re: Problem in using LINQ to SQL


Quote:

Originally Posted by ck9663

Where's the part that insert the record?

-- CK

Hey this is LINQ - Language INtergrated Query

User newUser = new User // Create a new object
{
RealName = txtRName.Text,
UserName = txtSignUpUserName.Text,
Password = pwbSignUpPassword.Password,
Country = ComCountry.Text,



};
context.Users.InsertOnSubmit(newUser); // Submit the new object 2 da db


context.SubmitChanges();
Reply


Similar Microsoft SQL Server bytes