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
natchaya khamkuna
NA
31
23.6k
Help me please , How to write a loop of data into Database by Linq
Jun 27 2011 9:48 AM
my code as below :
private void btnOpenRead_Click(object sender, EventArgs e)
{
try
{
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Text Files(*.txt)|*.txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
label1.Text = openFileDialog1.FileName;
StreamReader sr = new StreamReader(openFileDialog1.FileName);
ClockRecord = sr.ReadLine();
while (ClockRecord != "")
{
day = ConvertNumber(ClockRecord.Substring(5, 2));
month = ConvertNumber(ClockRecord.Substring(7, 2));
year = ConvertNumber(ClockRecord.Substring(9, 4));
hour = ConvertNumber(ClockRecord.Substring(13, 2));
minute = ConvertNumber(ClockRecord.Substring(15, 2));
dt = new DateTime(year, month, day, hour, minute, 0);
ClockRecord = sr.ReadLine();
}
}
}catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
static int ConvertNumber(string text)
{
int i;
if(Int32.TryParse(text,out i))
return i;
MessageBox.Show("Invalid data: ", text);
return 0;
}
______________________
I now can separated the string But I don't know how to write to database .
for example I try : (Linq)
Times t = new Times();
t.Emp_Code = ClockRecord.Readline.Substring(5,2);
This will write to database only one record. I don't know how to make a loop . Since do not have line to count .
Expert help me please ..
Pang (Thailand)
Reply
Answers (
1
)
LINQ in HTML 5
LINQ to Entities query and Distinct on GUID