我在asp.net中创建了一个网站,除了用户注册表单外,一切正常。我的表单不是将数据发送到数据库。我可以通过在数据库中创建用户信息来登录该网站。
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);
}
}
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);
}
}
有人可以帮助我纠正htis
答案 0 :(得分:0)
使用SQL事件探查器拦截数据库调用。这将告诉您它是否甚至到达数据库。
如果是,可以从那里直接将语句复制到SQL Manager中并执行它。
在许多情况下,由于数据格式不正确,或者将null传递给非可空列。考虑到您也在传递日期,与数据库中的列定义相比,可能是格式错误。
如果以上所有方法都失败,发布数据库架构也会有所帮助。
答案 1 :(得分:0)
我要检查的第一件事是甚至调用 send_data 方法。我们没有看到表单和给定的代码没有指出如何调用此方法。您是否有一个控制事件(如按钮点击)调用一个调用 send_data 方法的方法?如果是,控件是否将 AutoPostback 设置为 true ?
我建议在方法开始时设置一个断点并确保你到达那里。