【发布时间】:2015-04-14 17:44:44
【问题描述】:
这是错误
“/Kibritak3”应用程序中的服务器错误。
列名“名称”无效。 列名“电话”无效。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Data.SqlClient.SqlException:列名“名称”无效。 列名“电话”无效。
来源错误:
在当前网络请求的执行过程中产生了一个未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。
堆栈跟踪:
its just come if i write this code
**
if (Literal1.Text == "Data inserted successfully")
{
Response.Redirect("http://localhost:1038/Kibritak3/CompanyHomePage.aspx");
}
else {
txtName.Text = "";
txtEmail.Text = "";
txtPhone.Text = "";
}
**
and without it evrything is ok
-------------------------
full code:
public void refress()
{
txtName.Text = "";
txtEmail.Text = "";
txtPhone.Text = "";
txtLocation.Text = "";
txtHistory.Text = "";
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
SqlCommand cmd = new SqlCommand("insert into Com_INFO(Name,Email,Phone,Location,History) values('" + txtName.Text + "','" + txtEmail.Text + "','" +txtPhone.Text+ "','" +txtLocation.Text+ "','"+txtHistory.Text+"')", con);
cmd.CommandType = CommandType.Text;
try
{
con.Open();
cmd.ExecuteNonQuery();
Literal1.Text = "Data inserted successfully";
con.Close();
refress();
}
catch (Exception ex)
{
Literal1.Text = ex.Message;
}
if (Literal1.Text == "Data inserted successfully")
{
Response.Redirect("http://localhost:1038/Kibritak3/CompanyHomePage.aspx");
}
else {
txtName.Text = "";
txtEmail.Text = "";
txtPhone.Text = "";
}
}
}
【问题讨论】:
-
这不是堆栈跟踪。
-
您的数据库表没有您认为的列。此外,为了理智,学习使用参数……尤其是在 Web 应用程序中! stackoverflow.com/q/17509169/327083
-
没有看到您在数据库中访问的表的结构,除了您的数据库列名与您引用的名称不匹配之外,我们没有什么可以说的在您的代码中,这正是错误消息告诉您的内容。此外,J... 是正确的。您的问题中显示的代码应该永远投入生产。很危险。
-
亲爱的 Sani ...我有一个列,我说在没有 if 语句的情况下数据保存良好
-
在
Literal1.Text = "Data inserted successfully";行放置一个断点,如果断点真的被命中,请告诉我们。
标签: c#