0
protected void Button1_Click(object sender, EventArgs e)
{
    string insrt = "insert into book_mas_det(book_date,book_from,book_to,travel_date,return_date,adult_pax,child_pax,travel_class,contact_name,pnr_no,tot_amt,adv_amount,travler_rmks,agent_rmks) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n)";
    string insrt2 = "insert into book_mas_det(book_date,book_from,book_to,travel_date,adult_pax,child_pax,travel_class,contact_name,pnr_no,tot_amt,adv_amount,travler_rmks,agent_rmks) values (@a,@b,@c,@d,@f,@g,@h,@i,@j,@k,@l,@m,@n)";
    MySqlCommand cmd = new MySqlCommand(insrt, conn);
    MySqlCommand cmd2 = new MySqlCommand(insrt2, conn);
    if (MultiView1.ActiveViewIndex == 1)
    {

        cmd.Parameters.AddWithValue("@a", txtbookingdate.Text);
        cmd.Parameters.AddWithValue("@b", ddlfrom.SelectedValue);
        cmd.Parameters.AddWithValue("@c", ddlto.SelectedValue);
        cmd.Parameters.AddWithValue("@d", txtdeprtr.Text);
        cmd.Parameters.AddWithValue("@e", txtreturn.Text);
        cmd.Parameters.AddWithValue("@f", txtadult.Text);
        cmd.Parameters.AddWithValue("@g", txtchild.Text);
        cmd.Parameters.AddWithValue("@h", ddlclass.SelectedValue);
        cmd.Parameters.AddWithValue("@i", txtcontpername.Text);
        cmd.Parameters.AddWithValue("@j", txtcontmobile.Text);
        cmd.Parameters.AddWithValue("@k", txtamnttocharge.Text);
        cmd.Parameters.AddWithValue("@l", txtadvamnt.Text);
        cmd.Parameters.AddWithValue("@m", txtcmnttrav.Text);
        cmd.Parameters.AddWithValue("@n", txtcmntagnt.Text);

    }
    else if (MultiView1.ActiveViewIndex == 0)
    {
        cmd2.Parameters.AddWithValue("@a", txtbookingdate.Text);
        cmd2.Parameters.AddWithValue("@b", ComboBox1.SelectedItem.Text);
        cmd2.Parameters.AddWithValue("@c", ComboBox2.SelectedItem.Text);
        cmd2.Parameters.AddWithValue("@d", TextBox1.Text);

        cmd2.Parameters.AddWithValue("@f", DropDownList1.Text);
        cmd2.Parameters.AddWithValue("@g", DropDownList2.Text);
        cmd2.Parameters.AddWithValue("@h", DropDownList3.SelectedItem.Text);
        cmd2.Parameters.AddWithValue("@i", txtcontpername.Text);
        cmd2.Parameters.AddWithValue("@j", txtcontmobile.Text);
        cmd2.Parameters.AddWithValue("@k", txtamnttocharge.Text);
        cmd2.Parameters.AddWithValue("@l", txtadvamnt.Text);
        cmd2.Parameters.AddWithValue("@m", txtcmnttrav.Text);
        cmd2.Parameters.AddWithValue("@n", txtcmntagnt.Text);
    }
    conn.Open();
    cmd.ExecuteNonQuery();
    cmd2.ExecuteNonQuery();
    conn.Close();
    string display = "Booking Details is added successfully";
    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);
}

这是我用于多视图数据库连接的 .cs 代码。实际上,我有 3 个单向视图,往返和多城市,对于前两个视图,我将使用这些代码进行数据库连接。但我无法获得。错误正在给出..“命令执行期间遇到致命错误”...如何解决这个...??..

4

1 回答 1

0

您正在使用:
cmd.Parameters.AddWithValue("@i", txtcontpername.Text);

像这样尝试: cmd.Parameters.Add("@i", txtcontpername.Text);

于 2013-11-13T06:36:10.473 回答