我正在开发一个webproject,我在ASP.NET中创建了一个SQL数据源,用于从我的数据库中获取数据。插件工作,看起来像这样。
//Data put in textboxes gets inserted into DB
SqlConnection con6 = new SqlConnection(ConfigurationManager.ConnectionStrings["jaklin11ConnectionString"].ConnectionString);
con6.Open();
string cmd = "INSERT INTO [Workout] (Date, Time, Distance, Email, Activity) VALUES (@Date, @Time, @Distance, @Email, @Activity)";
SqlCommand insertWorkout = new SqlCommand(cmd, con6);
insertWorkout.Parameters.AddWithValue("@Date", textDateWorkout.Text);
insertWorkout.Parameters.AddWithValue("@Time", textTimeWorkout.Text);
insertWorkout.Parameters.AddWithValue("@Distance", textDistanceWorkout.Text);
insertWorkout.Parameters.AddWithValue("@Activity", ddlrunningwalking.Text);
insertWorkout.Parameters.AddWithValue("@Email", textEmailWorkout.Text);
try
{
insertWorkout.ExecuteNonQuery();
con6.Close();
Response.Redirect("~/UserPages/Workout.aspx"); //Refresh the page after addning workout
}
catch (Exception ex)
{
lblError.Text = (ex.Message); //Otherwise error
}
}
}
它工作得非常好,当我检查我的SQL服务器时,它会将数据放在正确的位置。
然而,我的数据源FORMVIEW
不理解会话,并在User2登录时显示User1统计信息。我无法弄清楚原因。
**Code for the gridview**
SELECT * FROM [Workout] WHERE ([Email] = @Email) ORDER BY [Date] DESC,