'SqlConnection'不包含'Parameters'的定义

时间:2021-09-11 16:57:24

where am I going wrong?

我哪里错了?

            con.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email.Text;
            con.Parameters.Add("@Password", SqlDbType.VarChar).Value = Password.Text;
            con.Parameters.Add("@ID", SqlDbType.Int).Value = UserID.Text;
            con.Parameters.Add("@AccountType", SqlDbType.Int).Value = AccType.Text;

3 个解决方案

#1


1  

you want to do something like this. This will make sure your connection is open and then disposed when done. And will add all your parameters.

你想做这样的事情。这将确保您的连接处于打开状态,然后在完成后处理。并将添加所有参数。

using (SqlConnection cn = new SqlConnection(ConString))
            {
                try
                {
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand(proc, cn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Email", myEmail);
                        cmd.Parameters.AddWithValue("@Password", myPass);
                        cmd.Parameters.AddWithValue("@ID", myID);
                        cmd.Parameters.AddWithValue("@AccountType", myAccount);

                        cmd.ExecuteNonQuery();
                    }
                }
                catch (SqlException)
                {
                    Debug.WriteLine("Error in SQL cmd!");
                    throw;
                }

#2


1  

You add parameters to a SqlCommand object, like so:

您将参数添加到SqlCommand对象,如下所示:

using (SqlConnection conn = new SqlConnection(connectionString)) {
    using (SqlCommand cmd = new SqlCommand(commandText, conn)) {
        // There're three command types: StoredProcedure, Text, TableDirect
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email.Text;
        cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = Password.Text;
        cmd.Parameters.Add("@ID", SqlDbType.Int).Value = UserID.Text;
        cmd.Parameters.Add("@AccountType", SqlDbType.Int).Value = AccType.Text;

        conn.Open();
        return cmd.ExecuteNonQuery();
    }
}

#3


0  

That is correct. SqlConnection does not contain a definition for Parameters.

那是正确的。 SqlConnection不包含Parameters的定义。

You are looking for SqlCommand.

您正在寻找SqlCommand。

#1


1  

you want to do something like this. This will make sure your connection is open and then disposed when done. And will add all your parameters.

你想做这样的事情。这将确保您的连接处于打开状态,然后在完成后处理。并将添加所有参数。

using (SqlConnection cn = new SqlConnection(ConString))
            {
                try
                {
                    cn.Open();
                    using (SqlCommand cmd = new SqlCommand(proc, cn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Email", myEmail);
                        cmd.Parameters.AddWithValue("@Password", myPass);
                        cmd.Parameters.AddWithValue("@ID", myID);
                        cmd.Parameters.AddWithValue("@AccountType", myAccount);

                        cmd.ExecuteNonQuery();
                    }
                }
                catch (SqlException)
                {
                    Debug.WriteLine("Error in SQL cmd!");
                    throw;
                }

#2


1  

You add parameters to a SqlCommand object, like so:

您将参数添加到SqlCommand对象,如下所示:

using (SqlConnection conn = new SqlConnection(connectionString)) {
    using (SqlCommand cmd = new SqlCommand(commandText, conn)) {
        // There're three command types: StoredProcedure, Text, TableDirect
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email.Text;
        cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = Password.Text;
        cmd.Parameters.Add("@ID", SqlDbType.Int).Value = UserID.Text;
        cmd.Parameters.Add("@AccountType", SqlDbType.Int).Value = AccType.Text;

        conn.Open();
        return cmd.ExecuteNonQuery();
    }
}

#3


0  

That is correct. SqlConnection does not contain a definition for Parameters.

那是正确的。 SqlConnection不包含Parameters的定义。

You are looking for SqlCommand.

您正在寻找SqlCommand。