简体   繁体   中英

ASP. net registration form database linking issue

I have created a website in asp.net everything is working fine except user registration form. My form is not sending data to the database. I am able to login to the website by making user info in database.

  private void dend_data_user_login(string email_id, string user_id) { Connection connection = new Connection(); SqlConnection selectConnection = new SqlConnection(connection.connect_method()); DataSet dataSet = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter("select * from User_Login ", selectConnection); adapter.Fill(dataSet, "User_Login"); DataTable dataTable = dataSet.Tables[0]; DataRow row = dataTable.NewRow(); row[1] = email_id; row[2] = this.txt_password.Text; row[3] = user_id; dataTable.Rows.Add(row); new SqlCommandBuilder(adapter); adapter.Update(dataTable); } [ScriptMethod, WebMethod] public static List<string> GetCountries(string prefixText) { List<string> list = new List<string>(); string connectionString = new Connection().connect_method(); SqlConnection selectConnection = new SqlConnection(connectionString); SqlDataAdapter adapter = new SqlDataAdapter("Select Companyname from Store_details where Companyname Like '" + prefixText + "%'order by Companyname", selectConnection); DataSet dataSet = new DataSet(); adapter.Fill(dataSet, "Store_details"); DataTable table = dataSet.Tables[0]; new CultureInfo("en-US"); if (table.Rows.Count > 0) { for (int j = 0; j < table.Rows.Count; j++) { string item = table.Rows[j][0].ToString(); list.Add(item); } return list; } SqlConnection connection3 = new SqlConnection(connectionString); SqlDataAdapter adapter2 = new SqlDataAdapter("Select distinct Companycode from Coupon_details where Description Like '%" + prefixText + "%'order by Companycode", connection3); DataSet set2 = new DataSet(); adapter2.Fill(set2, "Coupon_details"); DataTable table2 = set2.Tables[0]; for (int i = 0; i < table2.Rows.Count; i++) { string id = table2.Rows[i][0].ToString(); string str4 = new find_company_name().fatch_Store_names(id); list.Add(str4); } return list; } protected void Page_Load(object sender, EventArgs e) { if (!base.IsPostBack) { string str = DateTime.UtcNow.AddHours(5.0).AddMinutes(30.0).ToString("dd/MM/yyyy"); this.Session["today"] = str; int minValue = 1; int maxValue = 9; Random random = new Random(); this.Label1.Text = random.Next(minValue, maxValue).ToString(); int num3 = 10; int num4 = 20; Random random2 = new Random(); this.Label2.Text = random2.Next(num3, num4).ToString(); } } [WebMethod] public static string ProcessIT(string name, string address) { return ("Welcome Mr. " + name + ". Your address is '" + address + "'."); } private void send_data(string email_id, string user_id) { try { this.lblmessage.Text = ""; this.send_dta_user_registeration(email_id, user_id); this.dend_data_user_login(email_id, user_id); this.Session["User"] = email_id; if (this.Session["repoansid"] != null) { string url = this.Session["repoansid"].ToString(); base.Response.Redirect(url); } else { base.Response.Redirect("Default.aspx"); } } catch (Exception exception) { new ClassException().submit_exception(exception.ToString()); } } private void send_dta_user_registeration(string email_id, string user_id) { Connection connection = new Connection(); SqlConnection selectConnection = new SqlConnection(connection.connect_method()); DataSet dataSet = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter("select * from User_Register_info ", selectConnection); adapter.Fill(dataSet, "User_Register_info"); DataTable dataTable = dataSet.Tables[0]; DataRow row = dataTable.NewRow(); row[1] = user_id; row[2] = "SELF"; row[3] = this.txt_name.Text; row[4] = email_id; row[5] = this.Session["today"].ToString(); row[6] = Convert.ToInt32(DateTime.UtcNow.AddHours(5.0).AddMinutes(30.0).ToString("yyyyMMdd")); row[7] = "UNBLOCK"; dataTable.Rows.Add(row); new SqlCommandBuilder(adapter); adapter.Update(dataTable); } } 

}

Can someone help me how to correct htis

Use SQL Profiler to intercept the database calls. This will tell you if it is even getting to the database.

If it is, from there you can copy the statement into SQL Manager directly and execute it.

In many cases its due to incorrect formatting of data, or a null being passed to a non nullable column. Considering you are also passing in a date, it is likely that is in the wrong format compared to the column definition in the database.

Posting the DB schema could also help if all the above fail.

The first thing I would check is that the send_data method is even being called. We do not see the form and the given code does not indicate how this method is being called. Do you have an event on control (like a button click) calling a method calling the send_data method? If so, does the control have AutoPostback set to true ?

I suggest putting a break point at the start of the method and making sure that you even get there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM