Hello,
I want to find out if it is because of that fact that the userID was not fetched from the email link, that is why i am having this error?
Column name or number of supplied values does not match table definition
in line cmd.ExecuteNonQuery()
User Table sturucture
Uid, email, pass, con_pass, UserRole, Name, CreatedBy, image, CreateDate
public partial class NewTeamSignup : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True");
protected void Button1_Click(object sender, EventArgs e)
{
string CreatedBy = GetCreatedBy(Convert.ToInt32(Request.QueryString["Uid"]));
using (SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Users VALUES(@email,@pass,@con_pass,@UserRole,@CreatedBy,@CreateDate)"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@email", mailtxtbx.Text.Trim());
cmd.Parameters.AddWithValue("@pass", pass.Text.Trim());
cmd.Parameters.AddWithValue("@con_pass", conpass.Text.Trim());
cmd.Parameters.AddWithValue("@UserRole", 'U');
cmd.Parameters.AddWithValue("@CreatedBy", CreatedBy);
cmd.Parameters.AddWithValue("@CreateDate", DateTime.Now);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
private string GetCreatedBy(int id)
{
string CreatedBy = "";
using (SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand("SELECT Uid FROM Users WHERE Uid = @Id"))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection = con;
con.Open();
CreatedBy = Convert.ToString(cmd.ExecuteScalar());
con.Close();
}
}
return CreatedBy;
}
}