我正在开发一个网络项目,我在 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,