Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
13
Reply
I want to update the leftdays, Row by Row .not all at once.
Muhammad Ali
Feb 5 2017 12:42 AM
447
Reply
I want to Update the Leftdays Column Row by Row but the Statement which i am using for Update .its updates the whole Column with same value .. as datareader loop calculates the different value while looping ... how i can make work properly ..please comment the Code ..
private void button3_Click(object sender, EventArgs e)
{
myconnection.Open();
displayData();
string selectSql = "select * from employTable2";
SqlCommand com = new SqlCommand(selectSql, myconnection);
using (SqlDataReader read = com.ExecuteReader())
{
while (read.Read())
{
string first1 = read["salarydate"].ToString();
string Second1 = read["expiredate"].ToString();
TimeSpan t1 = Convert.ToDateTime(Second1) - DateTime.Now;
int daysleft = t1.Days;
SqlConnection myconnection1 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\documents and settings\muhammad\my documents\visual studio 2010\Projects\ProjectClock\ProjectClock\ClockDB.mdf;Integrated Security=True;User Instance=True;");
myconnection1.Open();
SqlCommand cmd1 = new SqlCommand("UPDATE employTable2 SET daysleft='" + daysleft.ToString() + "'", myconnection1);
cmd1.ExecuteNonQuery();
myconnection1.Close();
MessageBox.Show(t1.Days +"", "Days Left");
}
myconnection.Close();
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
13
)
Next Recommended Forum
Asp.net MVC . How to display name instead of ID in view page
Losing the data after post backing the page in jquery