0

という奇妙なエラーメッセージが表示されます

タイプ 'System.Data.SqlClient.SqlException' の初回例外が System.Data.dll` で発生しました

まだ理由がわかりません。登録とすべてを使用して .NET Web サイトを構築していますregistrationpart。これがコードです。うまくいけば、誰かが何が間違っているのか教えてくれます。私は答えを求めてグーグルで検索しましたが、とにかく正しいとは思えません。

public partial class UserPages_Register : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
   }

   protected void btnRegisterRegister_Click(object sender, EventArgs e)
   {
        //If passwords do not match, error
        if (textPasswordRegister.Text != textPassword2Register.Text)
        {
            lblErrorRegister.Text = "Passwords must match.";
        }
        else
        {
            //If user has uploaded image it gets saved in folder
            if (FileUpload1.HasFile)
            {
                string filename = Path.GetFileName(FileUpload1.FileName);
                FileUpload1.SaveAs(Server.MapPath("~/ProfileImages/") + filename);
                textProfileImageRegister.Text = (("~/ProfileImages/") + filename); 
            }
            else {
                //Otherwise a standard avatar is used
                textProfileImageRegister.Text = ("~/ProfileImages/Avatar.png");

                //Data put in textboxes gets inserted into DB
                SqlConnection con6 = new SqlConnection(ConfigurationManager.ConnectionStrings["jaklin11ConnectionString"].ConnectionString);
                con6.Open();
                string insCmd = "INSERT INTO [Users] (FirstName, LastName, Birthdate, Gender, Weight, Height, Email, Password, Town, AreaCode, ProfileImage) VALUES (@FirstName, @LastName, @Birthdate, @Gender, @Weight, @Height, @Email, @Password, @Town, @AreaCode, @ProfileImage)"; 
                SqlCommand insertUser = new SqlCommand(insCmd, con6);

                insertUser.Parameters.AddWithValue("@FirstName", textFirstNameRegister.Text);
                insertUser.Parameters.AddWithValue("@LastName", textLastNameRegister.Text);
                insertUser.Parameters.AddWithValue("@Birthdate", textBirthdateRegister.Text);
                insertUser.Parameters.AddWithValue("@Gender", ddlGenderRegister.Text);
                insertUser.Parameters.AddWithValue("@Weight", textWeightRegister.Text);
                insertUser.Parameters.AddWithValue("@Height", textHeightRegister.Text);
                insertUser.Parameters.AddWithValue("@Email", textEmailRegister.Text);
                insertUser.Parameters.AddWithValue("@Password", textPasswordRegister.Text);
                insertUser.Parameters.AddWithValue("@ProfileImage", textProfileImageRegister.Text);
                insertUser.Parameters.AddWithValue("@Town", texttown.Text);
                insertUser.Parameters.AddWithValue("@AreaCode", textareacode.Text);

            try
            {
                insertUser.ExecuteNonQuery();
                con6.Close();
                Session["Email"] = textEmailRegister.Text; //User gets logged in
                Response.Redirect("~/UserPages/Default.aspx"); //Send to startpage
            }
            catch (Exception)
            {
                lblErrorRegister.Text = "An error ocurred."; //Otherwise error
            }
4

3 に答える 3

0
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$     
ConnectionStrings:jaklin11ConnectionString %>" 
SelectCommand="SELECT [Activity], [Distance], [Date], [Time], [WorkoutID] FROM [Workout] 
WHERE ([Email] = @Email) ORDER BY [Date] DESC">
<SelectParameters>
<asp:SessionParameter Name="Email" SessionField="Email" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

データソースの CSS コードを変更しました。障害は、条件がなかったことです。そこで、WHERE Email = @Email を追加しました

于 2013-08-28T08:24:55.413 に答える