我得到这样的错误 [英] Am getting an error like this
本文介绍了我得到这样的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
total_seat = tot_seat.ExecuteScalar().ToString();
执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Data.SqlClient.SqlException:'1'附近的语法不正确。
我尝试了什么:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '1'.
What I have tried:
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string w = Request.QueryString["q"];
total_cost = Convert.ToInt16(lbl_total_price.Text);
if (DropDownList1.SelectedValue == "1")
ticket_price = 130;
if (DropDownList1.SelectedValue == "2")
ticket_price = 110;
int s = Convert.ToInt16(DropDownList2.SelectedValue);
ticket_price = ticket_price * s;
txt_ticket_price.Text = ticket_price.ToString(); ;
txt_ticket_price.Enabled = false;
txt_combo_price.Text = total_cost.ToString();
txt_combo_price.Enabled = false;
txt_service_fees.Text = "10";
txt_service_fees.Enabled = false;
int net_payable;
net_payable = total_cost + ticket_price;
txt_net_payable.Text = net_payable.ToString();
txt_net_payable.Enabled = false;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dataConnectionString"].ConnectionString);
con.Open();
int a = Convert.ToInt16(txt_combo_price.Text);
int b = Convert.ToInt16(txt_ticket_price.Text);
string c = Convert.ToString(DropDownList1.SelectedItem);
int d = Convert.ToInt16(DropDownList2.SelectedValue);
int f = Convert.ToInt16(txt_net_payable.Text);
string seat_typ = "1", total_seat = "1";
if (DropDownList1.SelectedValue == "1")
{
seat_typ = "select no_of_seats from booking where type='gold'";
total_seat = "select gold from seats";
}
if (DropDownList1.SelectedValue == "2")
{
seat_typ = "select no_of_seats from booking where type='silver'";
total_seat = "select silver from seats";
}
SqlCommand seat = new SqlCommand(seat_typ, con);
SqlCommand tot_seat = new SqlCommand(total_seat, con);
total_seat = tot_seat.ExecuteScalar().ToString();
int t_seat = Convert.ToInt16(total_seat);
string seat_info = seat.ExecuteScalar().ToString();
int drp = DropDownList2.SelectedIndex;
int s_info = Convert.ToInt16(seat_info);
s_info = s_info + drp;
string sql, no_of_seats, type;
if (s_info < t_seat)
{
if (DropDownList1.SelectedValue == "1")
{
type = "update booking set no_of_seats='" + s_info + "',seat_booked_now='gold' where type='gold'";
sql = "insert into booking_info (username,gold_booked,combo_cost,ticket_cost,seat_type,no_of_seats,net_payable) values('" + w + "','" + s_info + "','" + a + "','" + b + "','" + c + "','" + d + "','" + f + "')";
}
else
{
type = "update booking set no_of_seats='" + s_info + "',seat_booked_now='silver' where type='silver'";
sql = "insert into booking_info (username,silver_booked,combo_cost,ticket_cost,seat_type,no_of_seats,net_payable) values('" + w + "','" + s_info + "','" + a + "','" + b + "','" + c + "','" + d + "','" + f + "')";
}
SqlCommand typ = new SqlCommand(type, con);
SqlCommand cmd = new SqlCommand(sql, con);
typ.ExecuteNonQuery();
cmd.ExecuteNonQuery();
}
else
Response.Write("not enough seats available");
}
这是代码..请帮助我
this is the code..please help me
推荐答案
其验证问题
将其改为此
its validation issue
change it to this
SqlCommand seat = new SqlCommand(seat_typ, con);
SqlCommand tot_seat = new SqlCommand(total_seat, con);
string seat_typ = "1", total_seat = "1";
if (DropDownList1.SelectedValue == "1")
{
seat_typ = "select no_of_seats from booking where type='gold'";
total_seat = "select gold from seats";
total_seat = tot_seat.ExecuteScalar().ToString();
}
if (DropDownList1.SelectedValue == "2")
{
seat_typ = "select no_of_seats from booking where type='silver'";
total_seat = "select silver from seats";
total_seat = tot_seat.ExecuteScalar().ToString();
}
下拉列表值不同,因此它将命令设为1,因此错误发生在sql server
the dropdownlist value is different so it is taking the command as "1", so the error has occurred in sql server
这篇关于我得到这样的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文